From patchwork Fri Aug 11 21:51:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 134749 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp1390348vqi; Fri, 11 Aug 2023 15:25:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGHILmHMZMeTFm3ZQxoTXBOZJR/cVyU0e6QrBebkp2Nl1nj9db4vOV3wxCKZeEKZv1wrLRE X-Received: by 2002:a05:6a20:5482:b0:134:73f6:5832 with SMTP id i2-20020a056a20548200b0013473f65832mr4983116pzk.16.1691792726554; Fri, 11 Aug 2023 15:25:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691792726; cv=none; d=google.com; s=arc-20160816; b=VgzSnNYnMSOxOU4uccCyZODdFkpuusG9/9XXOjB4gXXmSRE7oMsqu6x8W5eOhpLADJ 6+0/iwqTfC4ZNGwoJRPPFreSmubnXynVHjmNKhoTKH3xuZh2WKVPPA9ZbdtA0QyOtizM feQn1ZinH1IaKkYEgv+c0ZuNedS4zsQABO3/SnisUjlA/dkr7CQb7PuCtx0RiFjMMUb9 JCD9XhLJpXeW5xMPrgkJbf4OUdHYZiTp+hNPkx80Hgfq7tcLm7AgeD7ckEPUyFlzafEX iOAYURkChzlNRg8+19vnU3/cN65tLzPq4pjbHuXOk31XnagXIxDm8a4GlhNOhFa2YeTL JViQ== 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=9RSN2EY2cJTW9zDsZRZuyf2aqRmAybo3jg1zS7CH0eo=; fh=2/wD3Wxskfa9AcaWsJc6DzZ67+LVSLroI/gZJKhbDmM=; b=G4tQxIWvHBzncEENhGh0/67HmFZ3379uhgKS6kIqFDfq/lf52c7o64Wg5tjdIa8LxQ 5B2YLHVKyWeVA+nGIR0+py1RUa94lCMz5pRTgnvyvfDdkoS1mtmd1gw+Kr7Z/zfV0tlZ x5LmOIo5raTU6iesQ+WIlbgot4fuC1640hOmFyqIviUOseXSI6wjQWs18YCdITrNNp2g L32uwPE2i/ooMowAAAGU+hM8xUBAo98E2mFUJD5ntZKatQN1jEF1/DRi1uHCAH69BbhO Z0BZL5sYz+gq6+JDLe0+pQOLCOiV33bS+Ni8IziKXR748RrdgUPGinBoTmm97xjXFsO9 9Ttg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p28-20020a056a0026dc00b006871e641c8dsi3986077pfw.12.2023.08.11.15.25.12; Fri, 11 Aug 2023 15:25:26 -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 S237000AbjHKVwP (ORCPT + 99 others); Fri, 11 Aug 2023 17:52:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235401AbjHKVwO (ORCPT ); Fri, 11 Aug 2023 17:52:14 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E957271B; Fri, 11 Aug 2023 14:52:10 -0700 (PDT) X-QQ-mid: bizesmtp69t1691790715t2l3imm8 Received: from linux-lab-host.localdomain ( [116.30.128.116]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 12 Aug 2023 05:51:53 +0800 (CST) X-QQ-SSF: 01200000000000E0X000000A0000000 X-QQ-FEAT: jGGC4gWX7WFEuWrQD10QYevA6rKFR5eyLN27zADU7mMJyUa1X6F5wj5b8c1PO ER8oXLqoaZcj68vp2XW1IvvzWMXYjLid4rTDbWxcHY9+xK0LZ6TboYz9xrN1UuKrfZPeivH Xhx+frlWCSJTPIl4qTvNiv+IIPg62gxZBtdjgSzG1OWsfAsHQZwMgx7V1TgW3uPw9evoaY9 f/3qSx8aKzolxDdGprJ9lCbNnqC8BdKQhSeoDf1ZVL0vz1omtIq9sC7KeFcpXHcLENpcFN+ ZEMfFnvLJZED4528TgM/+SpuC2OxOWzKeNxwVnytS785YBa97JXf5RSeKCPgFQkYpErIUmN JyXdyk2gkVM2i9Ad6ukNE5KRQK4tVquu5jqDZvRRUNb6m1LNpMtGj4GfqQLSUQA0SHWLMTn X-QQ-GoodBg: 0 X-BIZMAIL-ID: 14313426769615256479 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, david.laight@aculab.com, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, tanyuan@tinylab.org, thomas@t-8ch.de Subject: [PATCH v6 2/2] tools/nolibc: fix up size inflate regression Date: Sat, 12 Aug 2023 05:51:53 +0800 Message-Id: <96624cc918092737d35dd539d184de06dba7a9b8.1691788036.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 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, 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773973250235168189 X-GMAIL-MSGID: 1773973250235168189 As reported and suggested by Willy, the inline __sysret() helper introduces three types of conversions and increases the size: (1) the "unsigned long" argument to __sysret() forces a sign extension from all sys_* functions that used to return 'int' (2) the comparison with the error range now has to be performed on a 'unsigned long' instead of an 'int' (3) the return value from __sysret() is a 'long' (note, a signed long) which then has to be turned back to an 'int' before being returned by the caller to satisfy the caller's prototype. To fix up this, firstly, let's use macro instead of inline function to preserves the input type and avoids these useless conversions (1), (3). Secondly, since all of the sys_* functions have been converted to return integer, now, it is able to remove comparison to a 'unsigned long' -MAX_ERRNO (2) and restore the simple sign comparison as before. Suggested-by: Willy Tarreau Link: https://lore.kernel.org/lkml/20230806095846.GB10627@1wt.eu/ Signed-off-by: Zhangjin Wu --- tools/include/nolibc/sys.h | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index a28e7fbff448..e0b68d3532b6 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -27,23 +27,16 @@ #include "errno.h" #include "types.h" - -/* Syscall return helper for library routines, set errno as -ret when ret is in - * range of [-MAX_ERRNO, -1] - * - * Note, No official reference states the errno range here aligns with musl - * (src/internal/syscall_ret.c) and glibc (sysdeps/unix/sysv/linux/sysdep.h) - */ - -static __inline__ __attribute__((unused, always_inline)) -long __sysret(unsigned long ret) -{ - if (ret >= (unsigned long)-MAX_ERRNO) { - SET_ERRNO(-(long)ret); - return -1; - } - return ret; -} +/* Syscall return helper, set errno as -ret when ret < 0 */ +#define __sysret(arg) \ +({ \ + __typeof__(arg) __ret = (arg); \ + if (__ret < 0) { \ + SET_ERRNO(-__ret); \ + __ret = -1L; \ + } \ + __ret; \ +}) /* Functions in this file only describe syscalls. They're declared static so * that the compiler usually decides to inline them while still being allowed