Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp2565479rdg; Mon, 14 Aug 2023 06:42:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHGvPRGnuAHC2qAG7oQ2lTkzJ5oD3/8L6M/5za6xTUCO3zSCpUhmPrlkEJTtsJwJ5AVUyyp X-Received: by 2002:a05:6a20:7354:b0:133:2fb2:917d with SMTP id v20-20020a056a20735400b001332fb2917dmr10001319pzc.5.1692020555612; Mon, 14 Aug 2023 06:42:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692020555; cv=none; d=google.com; s=arc-20160816; b=hZ/KOTsW5mkcNuxnk8t61CI9IjYFigiVRjSIO/1zTIbmUkXg4+lFLxOXHP1jozQF6Z 5YMU0dct/qd2GojH7BEFeSFpTzQjh+k3+wOC6mnbqoID0yzTWuqdy8JhqU0uPz03wl84 7B0m5OkFLj92FK1m0M8NrvuwnjwtTyupe7cplcpfioIkqdKuvZ0zr4P3C2X5ctspdj72 WY8VX3ivNwDSSLI0ljbwSn6OcwKbEKXHg0ff90p0XQhcFYrIZrqrzC5hA3fY/zNlP+dR AwKmZByPiPv3GzK72cRWZ593jYzZZbqlzFtAkt07mNp1uPHawsWQQilyzetSuqpeVsWP 0sAQ== 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=Vtt8Ph+BQWkfPhu7NOEUpNxz1BY1UaG7MI05X8SfaIQ=; fh=oI4V1E1sOYSxoMH9Qqyd+8zC2tqA2GJRMmOAUvGHsck=; b=k9WqcSs/N9MuFqX3PFmiy/3BegYXrwVEJVyNElw+zwP/LwPSRtME6fI5ClhXzsAeuj CesOphrjmQvleSMy7MO9ismBoBbDsIIyzgml7zwS289mUnwa3qglGQGzyRtk6/eQTmd/ IL9IJcq8HOPOhhfKRCibrh3S9vkxkhprA5QbycQ20stZfix+CTjHDmZIUR6wAnLTlDee ii8ywqkl3fcQ2ck1Jnv/ZSL8D74CuYUcMrV7q5XdkW1xO/fkGSNRLhNolsrqiscf8RSC cA3pJ44ga7RUyaChkhzgQGmxdqk9GgXrUby37FfNujTe06jmdZ7HHd2oMb5OZ9MGQy05 dUYA== 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 f2-20020a635542000000b0055b0dcca8bbsi8104461pgm.21.2023.08.14.06.42.21; Mon, 14 Aug 2023 06:42:35 -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 S229882AbjHNNWr (ORCPT + 99 others); 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) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,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). > A quick check with godbolt doesn't show any sign extensions happening. I agree there's none here. Willy