From nobody Fri Dec 19 04:01:54 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4A2FC46467 for ; Tue, 10 Jan 2023 07:27:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234576AbjAJH1y (ORCPT ); Tue, 10 Jan 2023 02:27:54 -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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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-i= 386.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; \ }) =20 +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 bef= ore "sub $4, %esp\n" // the call instruction (args are aligned) --=20 2.17.5