Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp752474rwp; Wed, 12 Jul 2023 23:48:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlG8Avsm6ifismNHGFD8l2YhVzx5Zk3RSFHUADMMKXL3Z424SgwfW7At441sUeWuc0xczlMD X-Received: by 2002:a05:6a20:549d:b0:127:5f72:e4dd with SMTP id i29-20020a056a20549d00b001275f72e4ddmr727169pzk.44.1689230896927; Wed, 12 Jul 2023 23:48:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689230896; cv=none; d=google.com; s=arc-20160816; b=sPYAy86CE3R4KALoaFXcNiYM6twwVYJGQJaTz4fOF5SEYm5LJ7leg7pGxR3FBqDgDr lN+1VP5oqmJMHLMVPo6j7Igblr/gUupGhBF5pr+ZSu0MVFqva8UmEblEIWMO/zyMcgHS 3Km8FR3URDFvnUPhu3Nj7umG2cFFDXucZ+mM8q8LrpSrhGDX6ZDERH8w8fMurDnO1DB8 K+9EIqtYrCyMa/SWmqc0bQdVaWgbh6P+OqUFmIE4wSLJqPdoAMlcRKxIqdT2LAXbVYre tyWJ1G7QB7nB1rFDGze6CUZ0jPTw+OfpepC4dCOC/AS65TsYtPv6UbDwWDzUpnsqBKs7 sZhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=eptQqKRHsGCs8Rt/Mg7qWveCC+YVO58785gWRM4tKgY=; fh=ujwW7c4tbJyQEFqfHDIuJXTy68vjNzYK6N7f8YmL270=; b=CICvliZQ0N6qk/WS35zY64D6kJlJm42131Z46TuA0pCIVQGqxogAS7ikE/Q9t3HE5G KtaSf3TsV2tNSkL694yi+R0OF2RPASr524UsjjRJfaccx6JNGYhu8Mye+2GDcSOqVLXz V4QFd9c/W+GFIJHIztocUpcmbn0CtX49+eaHLZ8v29aIMdnXgR4jpe5G9iBH0ApO9Ons 27exuf7sCMKeGwlBiLqFelg+XN/KWHKsXUKQV3/T99VLh0b14QmBL42Cihb9az3lJxgp LHXX1FnXxCIHOwhpOxvCfxG7PEWbSjvRF62Pknbb8DiFt6CVYZg/nYNTjO4vOsFehMEf 7Chg== 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 s15-20020a056a00194f00b0064d28b68d8fsi4768381pfk.94.2023.07.12.23.48.03; Wed, 12 Jul 2023 23:48:16 -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; 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 S234045AbjGMGed (ORCPT + 99 others); Thu, 13 Jul 2023 02:34:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233560AbjGMGec (ORCPT ); Thu, 13 Jul 2023 02:34:32 -0400 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 716F110F2; Wed, 12 Jul 2023 23:34:30 -0700 (PDT) Received: (from willy@localhost) by mail.home.local (8.17.1/8.17.1/Submit) id 36D6YIxd022561; Thu, 13 Jul 2023 08:34:18 +0200 Date: Thu, 13 Jul 2023 08:34:18 +0200 From: Willy Tarreau To: Zhangjin Wu Cc: thomas@t-8ch.de, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v3 02/11] tools/nolibc: add new crt.h with _start_c Message-ID: References: <20230713061227.43222-1-falcon@tinylab.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230713061227.43222-1-falcon@tinylab.org> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,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 Hi Zhangjin, I haven't reviewed the rest yet but regarding this point: On Thu, Jul 13, 2023 at 02:12:27PM +0800, Zhangjin Wu wrote: > > > + /* find auxv */ > > > + i = 0; > > > + while (envp[i]) > > > + i++; > > > + _auxv = (void *)(envp + i + 1); > > > > Could be simplified a bit: > > > > _auxv = (void *) envp; > > while (_auxv) > > _auxv++; > > > > Yeah, it is better, but needs a little change. > > _auxv = (void *) envp; > while (*_auxv) > _auxv++; > _auxv++; Or just: _auxv = (void*)environ; while (*_auxv++) ; or: for (_auxv = (void*)environ; *_auxv++; ) ; Please also have a look at the output code, because at low optimization levels, compilers sometimes produce a better code with a local variable than with a global variable in a loop. Thus I wouldn't be that much surprised if at -O0 or -O1 you'd see slightly more compact code using: /* find envp */ environ = argv + argc + 1; /* find auxv */ for (auxv = environ; *auxv++) ; _auxv = auxv; than: /* find envp */ envp = argv + argc + 1; environ = envp; /* find auxv */ for (_auxv = environ; *_auxv++) ; Since it's going to become generic code, it's worth running a few tests to see how to best polish it. Thanks, Willy