From patchwork Mon Jul 10 18:01:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 118015 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp11362vqm; Mon, 10 Jul 2023 12:00:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlEDUOqeXI5HAV1yYas9VQ2J6g8i7ZPFHTIkSrVn7/m5vq8LYz4DPnP3PmbLwOGyrSo9aeOh X-Received: by 2002:a2e:8ec5:0:b0:2b6:de59:1ba4 with SMTP id e5-20020a2e8ec5000000b002b6de591ba4mr11864388ljl.20.1689015624170; Mon, 10 Jul 2023 12:00:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689015624; cv=none; d=google.com; s=arc-20160816; b=GgMWuE1BppLe5lWL4xc3i6QY6FTM54WSkrViCjmuAlgR/ugunyGT8RQqCd4SIgaJT2 HwBQ2Z3zhX57rL1K1+KGBe5bBtizK/tH+ZBjxoreayaT+4keH2xTOy04fHH5wdchbXL+ yIf1MtdIMRIgLrC5aHQGrVl7EYk3fdLcWOycnXfBys67t/MzXOyoRnRRltMD/nQnyenp RhAWrFUBK9vdW1mPJWaBeaHOBS6tasnx8/vLmc61F78dAc0k8kxCDuN0OSni4qm+lygn ANZ0wlvCqJdNH6hS7+LaGMrjOg/JQZl/1oQEry0aEk0+X7Yi/KCeiu4kDbRwiMaEDl21 96Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=j4n73VFmuGxhfomqR2/nLk4ArYjLEyVEY/j7DZYUO/w=; fh=JFL/hnEaWSzIms2FeXJkugx0AyzJ5ndUH+lDuCEW66A=; b=QzPRnR10ZmdNmgbVJZo3D93orsaI63n3Fek4HzQxHhNLYdDCEQ2Y6CDdT9spWwe7Md dcikwU5YGgjQZfj63CMAiBuQCCaQ2T8vPBcOdUIlHXl/gtohabLS3Jit3I3qyhUheoTj lXeeqys3AGIO0vup1urLjget4l7xPIo8HlQelf0bPNslzaBoAqkGiHC7K24z4k7lF1Hl u3dsZYHE9/Pe/RWm+OY759fY/Rl567j5c+Y8PXj2ZAD49gdAVVntk8lRb0I+AU+c0QzG pS4ocUIdLggj7FqfOhrXmMoMD6O8q3UKe+oyCR95ptkypErts0/9oq35P1yBTA5Pam1l RWUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=inTSR+fC; 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 p6-20020a170906614600b00993686e193csi223683ejl.53.2023.07.10.11.59.58; Mon, 10 Jul 2023 12:00:24 -0700 (PDT) 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; dkim=pass header.i=@weissschuh.net header.s=mail header.b=inTSR+fC; 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 S232999AbjGJSBm (ORCPT + 99 others); Mon, 10 Jul 2023 14:01:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230329AbjGJSBj (ORCPT ); Mon, 10 Jul 2023 14:01:39 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F1C012A for ; Mon, 10 Jul 2023 11:01:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1689012096; bh=DcJOOQNmpUkNsP7qakyEiaMLq0aFN20n09sMnLh0WJ4=; h=From:Date:Subject:To:Cc:From; b=inTSR+fC6JNiWyjaGmdlROBmV5GQmj8KYjMLrLokVlVSq7gVhz8bpIZ/ziBrQQWy3 8oYqX8xMxyfIjHf/S1NzdikS7asiAv4pg3NJbVAIAZqjMsjjd8q2hymHM+NFCwYPs2 0VHi16TQYUG5RP+ySMD03uWKE95PwMV1D0F8qps4= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 10 Jul 2023 20:01:34 +0200 Subject: [PATCH v2] tools/nolibc: completely remove optional environ support MIME-Version: 1.0 Message-Id: <20230710-nolibc-environ-v2-1-78b0c465338f@weissschuh.net> X-B4-Tracking: v=1; b=H4sIAH1HrGQC/3WMQQ7CIBBFr9LMWkyBtqgr72G6qDjIJAYapqKm4 e5i9+av3k/eW4ExETKcmhUSZmKKoYLaNWD9FO4o6FYZVKt0a2QrQnzQ1QoMmVIMwhxdp3qLg+4 7qNKc0NF7C17Gyp54iemz9bP8vX9TWYo6ow9a9kZPbji/kJjZ+qffB1xgLKV8AXmvCKixAAAA To: Willy Tarreau Cc: linux-kernel@vger.kernel.org, Zhangjin Wu , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1689012095; l=3528; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=DcJOOQNmpUkNsP7qakyEiaMLq0aFN20n09sMnLh0WJ4=; b=Ppz+7R6x3mnslqtdyf1zkfkfIxxQdSB9z6qcdjHlHJ2GNdNTzDwViyi34/CYTIde8nDbxg3/l /GsU0anWGehD/eHi2F3HVUEhN09NXsFvhmpbRTDJKCdXYOUjCvjHTRy X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: INBOX X-GMAIL-THRID: 1771061246899730464 X-GMAIL-MSGID: 1771061246899730464 In commit 52e423f5b93e ("tools/nolibc: export environ as a weak symbol on i386") and friends the asm startup logic was extended to directly populate the "environ" array. This makes it impossible for "environ" to be dropped by the linker. Therefore also drop the other logic to handle non-present "environ". Also add a testcase to validate the initialization of environ. Signed-off-by: Thomas Weißschuh --- Changes in v2: - add testcase to validate initialization and naming of environ as suggested by Willy - Link to v1: https://lore.kernel.org/r/20230710-nolibc-environ-v1-1-173831573af6@weissschuh.net --- tools/include/nolibc/stdlib.h | 12 ++---------- tools/testing/selftests/nolibc/nolibc-test.c | 7 ++++--- 2 files changed, 6 insertions(+), 13 deletions(-) --- base-commit: c9851cc968ac2ed87b83aee0cbec476b07d53a4c change-id: 20230710-nolibc-environ-79f425ce6354 Best regards, diff --git a/tools/include/nolibc/stdlib.h b/tools/include/nolibc/stdlib.h index 902162f80337..bacfd35c5156 100644 --- a/tools/include/nolibc/stdlib.h +++ b/tools/include/nolibc/stdlib.h @@ -83,11 +83,10 @@ void free(void *ptr) * declared as a char **, and must be terminated by a NULL (it is recommended * to set this variable to the "envp" argument of main()). If the requested * environment variable exists its value is returned otherwise NULL is - * returned. getenv() is forcefully inlined so that the reference to "environ" - * will be dropped if unused, even at -O0. + * returned. */ static __attribute__((unused)) -char *_getenv(const char *name, char **environ) +char *getenv(const char *name) { int idx, i; @@ -102,13 +101,6 @@ char *_getenv(const char *name, char **environ) return NULL; } -static __inline__ __attribute__((unused,always_inline)) -char *getenv(const char *name) -{ - extern char **environ; - return _getenv(name, environ); -} - static __attribute__((unused)) unsigned long getauxval(unsigned long type) { diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index ec0c20df76b2..f357bd815abc 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -44,8 +44,8 @@ #define SINT_MAX_OF_TYPE(type) (((type)1 << (sizeof(type) * 8 - 2)) - (type)1 + ((type)1 << (sizeof(type) * 8 - 2))) #define SINT_MIN_OF_TYPE(type) (-SINT_MAX_OF_TYPE(type) - 1) -/* will be used by nolibc by getenv() */ -char **environ; +/* will be used to test initialization of environ */ +static char **test_envp; /* will be used by some test cases as readable file, please don't write it */ static const char *argv0; @@ -786,6 +786,7 @@ int run_stdlib(int min, int max) * test numbers. */ switch (test + __LINE__ + 1) { + CASE_TEST(environ); EXPECT_PTREQ(1, environ, test_envp); break; CASE_TEST(getenv_TERM); EXPECT_STRNZ(1, getenv("TERM")); break; CASE_TEST(getenv_blah); EXPECT_STRZR(1, getenv("blah")); break; CASE_TEST(setcmp_blah_blah); EXPECT_EQ(1, strcmp("blah", "blah"), 0); break; @@ -1119,7 +1120,7 @@ int main(int argc, char **argv, char **envp) char *test; argv0 = argv[0]; - environ = envp; + test_envp = envp; /* when called as init, it's possible that no console was opened, for * example if no /dev file system was provided. We'll check that fd#1