From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5783EC001B0 for ; Mon, 14 Aug 2023 13:23:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229665AbjHNNWr (ORCPT ); Mon, 14 Aug 2023 09:22:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231148AbjHNNWe (ORCPT ); Mon, 14 Aug 2023 09:22:34 -0400 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8B8C5E77; Mon, 14 Aug 2023 06:22:31 -0700 (PDT) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 37EDM8bS019276; Mon, 14 Aug 2023 15:22:08 +0200 Date: Mon, 14 Aug 2023 15:22:08 +0200 From: Willy Tarreau To: David Laight 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 Message-ID: <20230814132208.GC18837@1wt.eu> References: <20230814082224.GA16761@1wt.eu> <20230814104226.7094-1-falcon@tinylab.org> <6fef903020954515abdcee7261918903@AcuMS.aculab.com> <20230814120941.GA18837@1wt.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@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). > A quick check with godbolt doesn't show any sign extensions happening. I agree there's none here. Willy