Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp5931527rwl; Mon, 9 Jan 2023 01:41:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXu2G3cO3zWlcN7qqwqw0s0BaNkKLgx1+atSTZrrIBeyLlAOck4lnHQvFCeEAZKcrhuOuCF8 X-Received: by 2002:aa7:d689:0:b0:46c:3f90:f5d9 with SMTP id d9-20020aa7d689000000b0046c3f90f5d9mr54646243edr.5.1673257260547; Mon, 09 Jan 2023 01:41:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673257260; cv=none; d=google.com; s=arc-20160816; b=l/5TZCa45iLKmTx71OGYVx68bpiAmVbj8u+oMUdEiuIAhCw/Q+Y9sUFMxFwkMlUduo GTWMeuj82aKAOQXvf8v+DUvI415BfwvGoDMut/FyW1N30n+N9YlcVwuACbKCfI3xwiZP WoB/1A3hvmXmlZglDVKlAY1XuKvJ4nJH7KWHQVQ5fxre8jGWDRTcAQuovtKl20fEjrk7 5F3rpG40O7Zihw+JatywRacqbUZ2AFtxAIWjhQ7ZOeZXxEF8it/LTRELU4rHa8ykvbNc HEPGo1JocQC0Vg50xN0X3qqz+YvHGf0lzbhQOUu0U+SvLIhn5i1BT5fy9Hnt8ANogaAL afhQ== 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=yv4/jJKmRTpZsVjy2jMv5qdCuR23vdFkPZfiUGVCr8muWWqjK5J2y/AhmRyeRy81yp JpHxE+GivlsJ6Nq0uHdhsjF5IyUDYPRddy75Kih7k0KILqzOP9VxYgk5M8M3BR9DSBW5 FWYZe6D0U2EogXIu+Z6cmKAUwfDNXW96urD7he20h8B7q9npLqjKKfIUhbnyJ5OtG4XM Kh8BHaTvYBr3351jMK8XqXai0BP8MTjflKrbUY6UdwIOfFk362RcPZt6f3TAqpxsn2bz rXHngI5jBjR+247cTBAk2eyfJpCFtN9JTCvte49cBWFhPe+P/0ly3HoFLcA6TbI7osgw ObPQ== 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 n11-20020a05640205cb00b0048d7c7eec7fsi10685549edx.285.2023.01.09.01.40.47; Mon, 09 Jan 2023 01:41:00 -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 S236505AbjAIItd (ORCPT + 54 others); Mon, 9 Jan 2023 03:49:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237005AbjAIIrv (ORCPT ); Mon, 9 Jan 2023 03:47:51 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DAA0B15F06 for ; Mon, 9 Jan 2023 00:43:32 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 3098gDoH027426; Mon, 9 Jan 2023 09:42:13 +0100 From: Willy Tarreau To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, Willy Tarreau Subject: [PATCH 07/22] tools/nolibc: export environ as a weak symbol on i386 Date: Mon, 9 Jan 2023 09:41:53 +0100 Message-Id: <20230109084208.27355-8-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20230109084208.27355-1-w@1wt.eu> References: <20230109084208.27355-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