Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7408680rwl; Mon, 9 Jan 2023 23:54:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXu/ceWOTDKrhuFiHxcknbDJp3l6cCB7BfiX4XiVjcG1q6XX2LcyKlBxrN1/Ruzu8l1nQryq X-Received: by 2002:a17:902:a984:b0:192:9a7d:c38a with SMTP id bh4-20020a170902a98400b001929a7dc38amr42761280plb.9.1673337287486; Mon, 09 Jan 2023 23:54:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673337287; cv=none; d=google.com; s=arc-20160816; b=EiNI6hqw8C7tTjtvY5y+oq5FftqafuQoj9LiT6YcS334UUg/KzAgdOPloTS9wHOauf wrATVE4N0LP2aIwXwHFfktvE5/gFAReLOnYOhb3iKMgkGwwteTlJYdpenDHn0R1TJqSQ 3zEt5CEMevm6GgIVSDw9nSvkKTxbA3umtxLWlc9jpxi3uaX0EQauXlBjzKkl/lJAWqKA 3SQs70x5ayzt5R4WPdhvRFe61DQoDQIqppzMMhYNeIGwSrW6gNKGCpqrj94L1wB4G6+Q KDDRuiDNEJh5tjKG90AbW4HaiCdf+demfu5uyyTsCCX1beelmCeB3u2FPaOGfNG1it4q tVqA== 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=ARmuHg6vFuaMAKsl9EE4ZTutUabGS78gZ8J6WV2/FwU=; b=F7f6wB4pC70XWRDbfn3XB6WxpnREUAfgyMrM96wQ9SaM3mmVnrqyfoi6KbhsjO/Rs+ bEHVrGSEJG7e1AcZRsxDSBWHiAiQTVGvSHFqS0VbyxrjHrt3g/TFa+0VHinguTIniFtw Yy1hDsC5KndUfhL4ArrGFnwS86xhEv22ZhIT1LFKLwsqQDS2t3gMbvLQEeSZRyNsq7B1 wUbltKHmIh+yI/AkyIUY7tpCwOaUIufJyA5qb3tVcSZ2nt7alJDzPov6iJZMKlVX5Ub2 1Cq/2JVQpIujrNK0pBqAB9CGY1dMnrn3dawxKWY7HaXaI6Svn0At6cbTzBRjQha5smBV avDw== 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 t203-20020a635fd4000000b0049b37046fb9si11714473pgb.243.2023.01.09.23.54.41; Mon, 09 Jan 2023 23:54:47 -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 S237948AbjAJH1x (ORCPT + 53 others); Tue, 10 Jan 2023 02:27:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237979AbjAJH1T (ORCPT ); Tue, 10 Jan 2023 02:27:19 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0C46D5FC5 for ; Mon, 9 Jan 2023 23:26:03 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 30A7OcbD003934; 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 07/22] tools/nolibc: export environ as a weak symbol on i386 Date: Tue, 10 Jan 2023 08:24:19 +0100 Message-Id: <20230110072434.3863-8-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-i386.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i386.h index ef2a836ee667..60b586120727 100644 --- a/tools/include/nolibc/arch-i386.h +++ b/tools/include/nolibc/arch-i386.h @@ -178,6 +178,8 @@ struct sys_stat_struct { _eax; \ }) +char **environ __attribute__((weak)); + /* startup code */ /* * i386 System V ABI mandates: @@ -191,6 +193,7 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void) "pop %eax\n" // argc (first arg, %eax) "mov %esp, %ebx\n" // argv[] (second arg, %ebx) "lea 4(%ebx,%eax,4),%ecx\n" // then a NULL then envp (third arg, %ecx) + "mov %ecx, environ\n" // save environ "xor %ebp, %ebp\n" // zero the stack frame "and $-16, %esp\n" // x86 ABI : esp must be 16-byte aligned before "sub $4, %esp\n" // the call instruction (args are aligned) -- 2.17.5