Received: by 2002:a05:7412:bb8d:b0:d7:7d3a:4fe2 with SMTP id js13csp15295rdb; Mon, 14 Aug 2023 08:14:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEfVp/lfiMMTiGzCZTi3ngiFypAvkz26IP/GAKY7bf7jwBdyCc4dX9V2UjgLTJ7Uf9SEKx9 X-Received: by 2002:a05:6a21:7787:b0:135:38b5:7e4e with SMTP id bd7-20020a056a21778700b0013538b57e4emr8574911pzc.59.1692026047456; Mon, 14 Aug 2023 08:14:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692026047; cv=none; d=google.com; s=arc-20160816; b=FnG51DYiZzAJFBqKtIFfFWdCsfA77A0bTkFkEknuonwJYS6e4AADMlLzp0WNwKvA0i Q46XxVy54WFy/NCyUf+Vx1nDhKVGjxHEq8zZoFV1p9NAqHg/gMrj5mEkBxbpSEraHvHw dmfMh0PNrRhN1fFbKseiuB/EnJv9aBW4K7xVhPhfSUW3NRuub5+Xoip2FBX1577e8CHV Sd46KX4E8raAiv2u/zX5J3dyOiFQdXNMuwBbsWwt8KXw8Zeu9Q+A1HZd1Lm5aayn/A7t o/Ai4h+Sd2g7ayt2qbWpjx35etiDMQNoThckmIFcPzcuTkMTzjdpB8LW+LIbjPxm/bAF JQSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=SN3jeP6AzztEsrLqXIjb4YFdQZx+u3IiGvV273X+7dY=; fh=DESv8J/ZwCIIIoJtbl6TU341KBLuJwdjdujGbq7taWE=; b=pzBNqw6VBrahV8JEd227YrE5EpJCuwHGWJ4k/tVuVcRDdRdh0On6Lyt7S0EvQanT0r dxs3vWOSG38JohNvjPWig9ndZeueVYKs+orqvf9P8Xbj7+7i3ZDtYwzchgvqyC7bCpPu gpuNgHuhSGZPZm/YWYMHio5NHl7lRLVNEjjg7pOHyN1TX3IU/J456SoDpYNzduSoTHDN /3o+T4NEpnt/S95aFhFbRWZfK2T9z/MsvCks0vBKH/enrQCvIJFacMrdyUknSH8te1IT BCWD8qoTDfqWzNmEK8HoAfSzwAMz6nOeK+9aC0KYG2NCUaPQmz9fAuNoY/Sj3BFaVgAO vVOg== 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 eb8-20020a056a004c8800b00670ab28fac3si8205279pfb.378.2023.08.14.08.13.51; Mon, 14 Aug 2023 08:14:07 -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 S231841AbjHNPEI (ORCPT + 99 others); Mon, 14 Aug 2023 11:04:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231629AbjHNPED (ORCPT ); Mon, 14 Aug 2023 11:04:03 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AB4918F; Mon, 14 Aug 2023 08:04:00 -0700 (PDT) X-QQ-mid: bizesmtp90t1692025423t74pom02 Received: from linux-lab-host.localdomain ( [116.30.128.116]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 14 Aug 2023 23:03:42 +0800 (CST) X-QQ-SSF: 01200000000000E0X000000A0000000 X-QQ-FEAT: RmDZc/K2LPHIjGTliFn1MDalUgmywfpO1nPYPxXK2+N9HkXb4PP3jEx+fNN8p ApphuAIN7plJLg6eY7lsSN3/PzoYcbgDk0lSIP+R+RJadbOuP+8ZmlxyOQDgwppi/SKVSJ1 SeoLvcWKtlmw7tCCgv+igmP6lTBgCnNszNNThTgkbE8AHMwoBkQ4m3fwV7ItQtyFhQo/xsd UImBYDa4O+x3NlfoB5Kdx5aG7AI8MKPmdXfWLY9nwRNdLmOC1kXmPQ2b1drvH/s4SmiIFXA brCyq8wsU+YR5H4Ign2y8RWJT93HX8Jew4xQ9GaDOgDBaPD26kLiYnMPyNLiiNfkeuAb2mU 8y8RmPW+k01PCb5NjKizGQ+JwpYmUj56mYEodA1Gr98WPOc+r5J62V6rNj0VA== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 6938916050489271949 From: Zhangjin Wu To: falcon@tinylab.org Cc: David.Laight@ACULAB.COM, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de, w@1wt.eu Subject: Re: [PATCH v5] tools/nolibc: fix up size inflate regression Date: Mon, 14 Aug 2023 23:03:41 +0800 Message-Id: <20230814150341.203817-1-falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230814141831.163031-1-falcon@tinylab.org> References: <20230814141831.163031-1-falcon@tinylab.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,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 > > On Mon, Aug 14, 2023 at 12:27:48PM +0000, David Laight wrote: > > > 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). > > > > Yes, that's something we can do (with the parenthesis around > > __typeof__(v) though). > > > > Yes, we need the parenthesis, this works: > > #define SET_ERRNO(v) ( errno = -(long)(v), ((__typeof__(v))-1)) > Willy, David, We still need "({})": #define SET_ERRNO(v) ({ errno = -(long)(v); (__typeof__(v))-1; }) to silence the warning: sysroot/x86_64/include/errno.h:13:42: warning: right-hand operand of comma expression has no effect [-Wunused-value] 13 | #define SET_ERRNO(v) ( errno = -(long)(v), (__typeof__(v))-1) | ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~ BR, Zhangjin > #define __is_unsigned_type(v) ((__typeof__(v))(-1) > (__typeof__(v))1) > #define __is_syserr(v) (__is_unsigned_type(v) ? (long)v & ~(-4095UL) : (v + 1 < (__typeof__(v))1)) > > #define __sysret(arg) \ > ({ \ > __typeof__(arg) __sysret_arg = (arg); \ > (!__is_syserr(__sysret_arg)) ? __sysret_arg : SET_ERRNO(__sysret_arg); \ > }) > > It looks better now, even for 'void *'. > > '(long)x & ~(-4095UL)' saves another 2+ bytes in some architectures: > > i386: 160 test(s): 158 passed, 2 skipped, 0 failed => status: warning 19256 > x86_64: 160 test(s): 158 passed, 2 skipped, 0 failed => status: warning 21740 > arm64: 160 test(s): 158 passed, 2 skipped, 0 failed => status: warning 25812 > arm: 160 test(s): 158 passed, 2 skipped, 0 failed => status: warning 22856 > mips: 160 test(s): 157 passed, 3 skipped, 0 failed => status: warning 22756 > ppc: 160 test(s): 158 passed, 2 skipped, 0 failed => status: warning 26380 > ppc64: 160 test(s): 158 passed, 2 skipped, 0 failed => status: warning 26756 > ppc64le: 160 test(s): 158 passed, 2 skipped, 0 failed => status: warning 27364 > riscv: 160 test(s): 158 passed, 2 skipped, 0 failed => status: warning 21758 > s390: 160 test(s): 157 passed, 3 skipped, 0 failed => status: warning 21936 > > BR, > Zhangjin