Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp2018940rwb; Sun, 6 Aug 2023 08:04:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHmgDJZTeQD07NZeIblY21KMnbyDA9IE/fZ6OlX9UfyV6Tplfo+5FppeSqV/fyv1INIqVYd X-Received: by 2002:a05:6a00:22d0:b0:687:520e:4b17 with SMTP id f16-20020a056a0022d000b00687520e4b17mr8772217pfj.8.1691334263261; Sun, 06 Aug 2023 08:04:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691334263; cv=none; d=google.com; s=arc-20160816; b=i12FnNG+qYxJNCu0l6TnO0BZs7xQE7axSCfx6QT/G9QR7Kum4aPJDfh6ss7KWqrMzF p33nwmARqS1RZhEcAmj+EILcBE1KH8vCIkxf5SC3N8oKyUhtFoyiiWia+lH9e1D8VDBp Ccg3J7EsW3praAh5Znwqxu9cQjd8Z9W5mzge8BCGNCW2bw7M9Y4k4tni9uVOVwpeX69Y An36rv9UL5yhKHC5JiMOuMxcFCvnLga/H86QPzXbrU/timPDjO2Z2DQYn9upnPromMDX hZ0PTzTugRW3GiDPEAjBrCCd3nqWGWSohDF6nWJuL/wpHAJaHAIBTizfq5dQuWS4GX9G AeCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=1z4w3Z0G/uDBMWj4iDCpzIW3758/EzTR6qSPtY1qwaY=; fh=hWvSKgORhUBL3eQSpnllPnYtc0jAAywWzmx4zVsB6ZE=; b=uyHgsPtl/hibdq07cTPGnc4q9Z+vMfgsddViRDqBAzaSA9OmOzfLNsiSR8rQu88Hdi cpjKeyKDfB9+W+3kj6S3FJJJMn9vou8OivnDhNClrFnv0sSIdCuYMKWXCLiAcT7XDgE7 h92UEVm60oRLT1n6cedBvR2jgYqhdkYxN32BtLi4a3a7s7xsfG8lxffS7jG3g0HFGpBN G4o/LHs8VHfZeHH1cH+KeJLtKjl91WhrPt1OFDh9Kc+fArBxI960CaeqO8+5XBq9NU7R l1ysKqbWOoRYafoUYr7OkmMIIbyz5pgetgxq6J0mSQZyAQRn7mSSXo8Ui/89uvOhlgSF 912w== 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 ds6-20020a056a004ac600b006875df23aa7si4459735pfb.360.2023.08.06.08.04.10; Sun, 06 Aug 2023 08:04:23 -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 S230253AbjHFNoM (ORCPT + 99 others); Sun, 6 Aug 2023 09:44:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229592AbjHFNoL (ORCPT ); Sun, 6 Aug 2023 09:44:11 -0400 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 426E1E7; Sun, 6 Aug 2023 06:43:59 -0700 (PDT) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 376Dhm1A019399; Sun, 6 Aug 2023 15:43:48 +0200 Date: Sun, 6 Aug 2023 15:43:48 +0200 From: Willy Tarreau To: Zhangjin Wu Cc: arnd@arndb.de, david.laight@aculab.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de Subject: Re: [PATCH] tools/nolibc: fix up size inflate regression Message-ID: <20230806134348.GA19145@1wt.eu> References: <20230806131921.52453-1-falcon@tinylab.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230806131921.52453-1-falcon@tinylab.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,T_SPF_HELO_TEMPERROR,T_SPF_TEMPERROR 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 On Sun, Aug 06, 2023 at 09:19:21PM +0800, Zhangjin Wu wrote: > As reported and suggested by Willy, the inline __sysret() helper > introduces three types of conversions and increases the size: Thanks Zhangjin. A few things: > --- a/tools/include/nolibc/compiler.h > +++ b/tools/include/nolibc/compiler.h > @@ -22,4 +22,13 @@ > # define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector"))) > #endif /* defined(__has_attribute) */ > > +/* > + * from include/linux/compiler.h > + * > + * Whether 'type' is a signed type or an unsigned type. Supports scalar types, > + * bool and also pointer types. > + */ > +#define is_signed_type(type) (((type)(-1)) < (type)1) > +#define is_unsigned_type(type) (!is_signed_type(type)) These names may conflict with application's local definitions. And since there's a single call place we should probably just inline it instead. > +#define __sysret(arg) \ > +({ \ > + __typeof__(arg) __sysret_arg = (arg); \ > + if (is_signed_type(__typeof__(arg))) { \ > + if (__sysret_arg < 0) { \ > + SET_ERRNO(-(int)__sysret_arg); \ > + __sysret_arg = -1L; \ > + } \ > + } else { \ > + if ((unsigned long)__sysret_arg >= (unsigned long)-MAX_ERRNO) { \ > + SET_ERRNO(-(int)__sysret_arg); \ > + __sysret_arg = -1L; \ > + } \ > + } \ > + __sysret_arg; \ > +}) I also found during my tests that this one can return a build error if the arg has "const" in its type, due to the error assignment. We need to think about reworking it as a ternary evaluation, it will be more reliable even if less readable. But let's not change this now, I'm on the changelog already. > /* Functions in this file only describe syscalls. They're declared static so > * that the compiler usually decides to inline them while still being allowed > @@ -94,7 +101,7 @@ void *sbrk(intptr_t inc) > if (ret && sys_brk(ret + inc) == ret + inc) > return ret + inc; > > - return (void *)__sysret(-ENOMEM); > + return (void *)__sysret((unsigned long)-ENOMEM); I noticed that one as well during my tests, but if we're purist, we're supposed to use (void*) for the cast and not (unsigned long), and it should allow to get rid of the outer cast. Regards, Willy