Received: by 2002:a05:7412:bb8d:b0:d7:7d3a:4fe2 with SMTP id js13csp656rdb; Mon, 14 Aug 2023 07:54:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKq8oRvvntbZ0Uwo5lVt2D1/dMaWk91g6LjZWOHpB0OsX5wlCwscuvUpog7/mowlwHAsOV X-Received: by 2002:a05:6808:8c5:b0:3a7:5d6e:dcee with SMTP id k5-20020a05680808c500b003a75d6edceemr9979034oij.44.1692024869841; Mon, 14 Aug 2023 07:54:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692024869; cv=none; d=google.com; s=arc-20160816; b=I5SxmH8X7dcQF77RJ2lFZCZxsQnrbJ4cKsJ1+h/yM4jzUTooyzSQ4NABBxm7UsO6vS LkQ+7s8xGQI8HsYeyEDrKNmQaBZLd1qeJSIcs/TJjaxptr5/JqHsioDUFGkDbYnV8dkQ hwitc2ZHfDiIYT3dk1/cuOVyZHQXyHmBAs0TuLpbGodP6rojYSFitmlBLKQsRvO2iwIi QO3B8x1uKm2mCr39uJK9SI51jpRzKCNwujyisKpvw/Eom/63+wC8YUmtp8JJn+Kcuqh6 Vl31ntVw8w6qQunZOME3TJC5SZDq3X8Oom/FzYdDdG6KpdmL20yMyrJVLTQSewjiUOnv gQmw== 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=pdlfDWDgES2HKpmypzdZo+m5yOZihXdboWLfZYE/1Xs=; fh=WKpSJcwFDakzu2YHZnx+PZ2BoB5/yxHnD/Z3EMBeXFA=; b=a+6GUQZRGZ9hb1n3CPzd9yvc2VwNL6D2UkIW/EOcmhZGM6bCyk8KOXIW00qKndVRnw UX1hlDaRwMOdYi6PzSxsq1KnUTixMKKAobJJgiAVNqszQOepMa/fbI6fMyYrtu6F/rHq 17Mjp8mEKSIX+zoFrlzc8mPjAxfVR0bhSj6eXDPcwdkppUFaI97ShwiCc7+3cQBlIesv OOV8Hii+L8xkJECV9WYBtS+cRIz5dib2a5c+W3derWtTbM8zqGA6jrsIfQeIvOiqG19O ZzbYV5tbwQvjypwJ5fmAy7R9pgWshrsTNQTGxeaQZxVQ7lK9spWBt9UBZQ56dyHJTCVR 7zyg== 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 y1-20020a636401000000b0056424e3bb74si8427572pgb.203.2023.08.14.07.54.16; Mon, 14 Aug 2023 07:54:29 -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 S231243AbjHNOTO (ORCPT + 99 others); Mon, 14 Aug 2023 10:19:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232248AbjHNOTE (ORCPT ); Mon, 14 Aug 2023 10:19:04 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4902EB5; Mon, 14 Aug 2023 07:19:02 -0700 (PDT) X-QQ-mid: bizesmtp71t1692022713tipf0ac0 Received: from linux-lab-host.localdomain ( [116.30.128.116]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 14 Aug 2023 22:18:32 +0800 (CST) X-QQ-SSF: 01200000000000E0X000000A0000000 X-QQ-FEAT: +ynUkgUhZJnVKMRPdEQMhoiCR4FCJkcCBXOej9bUdzwUIQ6MhBjDnysPFwL91 sShkDTh2uTtA3OJg3JinOFmGfsr4TQh96NT4zjPTdLbrTVYRHq81ob9/GppTB6rNPsBp/9U bgRKrdOqYh4VbEynpnLj/FU3ZPcKbyzAYBpMesH9VXdewiPKKhbf1S/idYVA+CTjc1fd7cE giGlkuli1c6kYwYMiJPlmJ1RbHtwrVNd/DYYjgxCw1bMCp3ZgG8jevRh7tqcaZzDgJwsKK8 FCLL/grkJmvTL0lhZaR6QrChdhy3h4GCa+XGGsiAIDtGp7c25MkHamdQKcH7jBWBpcJFoAJ ugGSAMUvRGR4dH8UNMXrB/FFBSinQpy/zx2WxDTIu0jX5itzng= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 15692046616011566384 From: Zhangjin Wu To: w@1wt.eu Cc: David.Laight@ACULAB.COM, arnd@arndb.de, falcon@tinylab.org, 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 Date: Mon, 14 Aug 2023 22:18:31 +0800 Message-Id: <20230814141831.163031-1-falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230814132208.GC18837@1wt.eu> References: <20230814132208.GC18837@1wt.eu> 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_BLOCKED,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)) #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 > > A quick check with godbolt doesn't show any sign extensions happening. > > I agree there's none here. > > Willy