Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp2553518rdg; Mon, 14 Aug 2023 06:21:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4IDlKe+6V/2G2+S+UaJQc+Bsx5wUsCB0FWxwsg0m/N142s4AwAsC4dtf93QduF90FHFGD X-Received: by 2002:aa7:dd55:0:b0:51e:309:2e12 with SMTP id o21-20020aa7dd55000000b0051e03092e12mr3572426edw.28.1692019288670; Mon, 14 Aug 2023 06:21:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692019288; cv=none; d=google.com; s=arc-20160816; b=i0zvmZa6K7rKU0oxCFnd5iNY0ZSUR5NQ0yGQhjD9SiVKaYAqjZxwJzjWKXIc/QpeTh z1FEv3iv3lBngduiGRJ3qneKNq4gWH/X+un+5qQTidN5nTr8b1sHfxttQyG1BnqZLtsO tMB7CpCB4KFLjtozP4ucvcaR5bHIwFfoJNkT+u1HTHY+V+HbXR7gMqNFjOofsZeVXF4o 6mVI7kK+D4+NziUqCF6y0ZhSjhUls/DesZ+mxXwoPY2x2KvtEHsfC5mKzzq58u/dnC+i fh1CRHqVj8g/kzqK5wSVIVEM1IvVeTp75+RMMF8KJSutRXAPW3UWyTli3SiSRRKPoLi0 Heyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=VN052DM2vxrdDLQ55nLsqR6QiP9cbtSM3kOnmYxgaSg=; fh=D+4HCK5n8fKsAsKer4VI30OCV5Z65MYGFzFF2NJsmCk=; b=rv7WE4ev5Ubu/IdyZ6XFeJk41XRBQ54uRKxCpcslPBHzZvUv2gfbO21LXVgICVoIsh LRshdD7t6+GTnnzT6yKwsPuRc8AWWYGTyu0gCs5JTmp4+lV8zPiXcsKm6UWsYNJnZpHu ekohndUgg8KKHyt3qEPjxljRMPwPaB/mmSUPz7Bl5GWXGQZqWq/J3H9+kmhPF0oI56k5 SmECA5umSTKNhCnB3cvv7Fna6Zesg5mcGIWEB3xcACxglN6oe3UMnVQXkUylOzwlXIUU Crj5T/BTsCF+ibcj76UNvd+K+HPyWQh9eY4jt64SiQmGBicGlwRHeB4TyN1/YHVinJk5 qEDg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y21-20020aa7d515000000b00525700b440asi121891edq.47.2023.08.14.06.21.04; Mon, 14 Aug 2023 06:21:28 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229930AbjHNM2a convert rfc822-to-8bit (ORCPT + 99 others); Mon, 14 Aug 2023 08:28:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230102AbjHNM2D (ORCPT ); Mon, 14 Aug 2023 08:28:03 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98D13E4A for ; Mon, 14 Aug 2023 05:28:02 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-265-t5D3hpR5Ou-FBcPeB1FmCg-1; Mon, 14 Aug 2023 13:28:00 +0100 X-MC-Unique: t5D3hpR5Ou-FBcPeB1FmCg-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Mon, 14 Aug 2023 13:27:48 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Mon, 14 Aug 2023 13:27:48 +0100 From: David Laight To: 'Willy Tarreau' CC: 'Zhangjin Wu' , "arnd@arndb.de" , "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" , "thomas@t-8ch.de" Subject: RE: [PATCH v5] tools/nolibc: fix up size inflate regression Thread-Topic: [PATCH v5] tools/nolibc: fix up size inflate regression Thread-Index: AQHZzpwIMKbqPe7hTkqs7/1zyBEHW6/pnUhggAAFJICAABLgYA== Date: Mon, 14 Aug 2023 12:27:48 +0000 Message-ID: References: <20230814082224.GA16761@1wt.eu> <20230814104226.7094-1-falcon@tinylab.org> <6fef903020954515abdcee7261918903@AcuMS.aculab.com> <20230814120941.GA18837@1wt.eu> In-Reply-To: <20230814120941.GA18837@1wt.eu> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,PDS_BAD_THREAD_QP_64, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 From: Willy Tarreau > Sent: 14 August 2023 13:10 > > Hi David, > > On Mon, Aug 14, 2023 at 11:15:51AM +0000, David Laight wrote: > > From: Zhangjin Wu > > > Sent: 14 August 2023 11:42 > > ... > > > [...] > > > > > > Sure it's not pretty, and I'd rather just go back to SET_ERRNO() to be > > > > > > honest, because we're there just because of the temptation to remove > > > > > > lines that were not causing any difficulties :-/ > > > > > > > > > > > > I think we can do something in-between and deal only with signed returns, > > > > > > and explicitly place the test for MAX_ERRNO on the two unsigned ones > > > > > > (brk and mmap). It should look approximately like this: > > > > > > > > > > > > #define __sysret(arg) \ > > > > > > ({ \ > > > > > > __typeof__(arg) __sysret_arg = (arg); \ > > > > > > (__sysret_arg < 0) ? ({ /* error ? */ \ > > > > > > SET_ERRNO(-__sysret_arg); /* yes: errno != -ret */ \ > > > > > > ((__typeof__(arg)) -1); /* return -1 */ \ > > > > I'm pretty sure you don't need the explicit cast. > > (It would be needed for a pointer type.) > > Can you use __arg < ? SET_ERRNO(-__arg), -1 : __arg > > > > Thinking, maybe it should be: > > > > #define __sysret(syscall_fn_args) > > ({ > > __typeof__(syscall_fn_args) __rval = syscall_fn_args; > > __rval >= 0 ? __rval : SET_ERRNO(-__rval), -1; > > }) > > Yeah almost, since arg is necessarily signed in this version, it's > just that I manually edited the previous macro in the mail and limited > the amount of changes to what was necessary. It's just that SET_ERRNO > only is an instruction, not an expression: > > #define SET_ERRNO(v) do { errno = (v); } while (0) > > Thus the return value doesn't even pass through it. That's why it was > so much simpler before. The rationale behind this was to bring the > ability to completely drop errno for programs where you didn't care > about it. It's particularly interesting when you don't need any other > data either as the program gets strunk from a complete section. Actually something like: #define SET_ERRNO(v) (errno = -(long)(v), __typeof__(v)-1) seems to work and allows the errno assignment be removed. Also works for pointer types (after a different compare). A quick check with godbolt doesn't show any sign extensions happening. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)