From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id C1B513858C33 for ; Sat, 25 Mar 2023 14:08:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C1B513858C33 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1679753320; bh=hFomyGjRNhKUXhoFBb5MvXIoEO456bObw1svM0MiZeE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HuzLsrUdtOV3pKf9S8IsLmRb6feU78kp31ZALiYT3V0lnSAI+qrnuQxv0jM/Fdu+P SMyBYGv1PTVuaJA5jsuj5rePaZzWhu4A086y9bujzQiUNIJVVi0rvRGKtOfgwbgyVI AQXqrYAoQYglbuihyeISXp+J0/uvI6FFqitR/vqk= Received: from stargazer.. (unknown [IPv6:240e:358:1172:ca00:dc73:854d:832e:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 6E5DC6647A; Sat, 25 Mar 2023 10:08:35 -0400 (EDT) From: Xi Ruoyao To: libc-alpha@sourceware.org Cc: caiyinyu , Wang Xuerui , Adhemerval Zanella Netto , Andreas Schwab , Florian Weimer , Xi Ruoyao Subject: [PATCH v2 1/5] linux: Add __ASSUME_SYSCALL_NAMED_WORKS to allow avoiding va_list for generic syscall Date: Sat, 25 Mar 2023 22:08:11 +0800 Message-Id: <20230325140815.4170296-2-xry111@xry111.site> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230325140815.4170296-1-xry111@xry111.site> References: <20230325140815.4170296-1-xry111@xry111.site> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,LIKELY_SPAM_FROM,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Currently GCC generates highly sub-optimal code on architectures where the calling convention prefers registers for argument passing. This is GCC PR100955. While it's technically a missed-optimization in GCC, it seems not trivial to fix (I've not seen any compiler which can optimize this properly yet). As the generic Linux syscall actually uses a fixed number of arguments, we can avoid va_list if possible and make the compiler do right thing. Add a macro __ASSUME_SYSCALL_NAMED_WORKS which should be defined if the calling convention treats (x named arguments + y variable arguments) exactly same as (x + y) named arguments, while each argument is either an integer of which the width is less than or equal to "long" or a pointer; and each argument can be fetched from the same register or the same offset from the stack pointer no matter how many (maybe zero) arguments are passed after it. --- sysdeps/unix/sysv/linux/syscall.c | 35 ++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/sysdeps/unix/sysv/linux/syscall.c b/sysdeps/unix/sysv/linux/syscall.c index a5a2843b73..ed5ad5afd5 100644 --- a/sysdeps/unix/sysv/linux/syscall.c +++ b/sysdeps/unix/sysv/linux/syscall.c @@ -16,9 +16,33 @@ License along with the GNU C Library. If not, see . */ -#include #include +#ifndef __ASSUME_SYSCALL_NAMED_WORKS +#include +#endif + +static inline long int +__syscall (long int number, long int a0, long int a1, long int a2, long int a3, + long int a4, long int a5) +{ + long int r = INTERNAL_SYSCALL_NCS_CALL (number, a0, a1, a2, a3, a4, a5); + if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (r))) + { + __set_errno (-r); + return -1; + } + return r; +} + +#ifdef __ASSUME_SYSCALL_NAMED_WORKS +long int +syscall (long int number, long int a0, long int a1, long int a2, long int a3, + long int a4, long int a5) +{ + return __syscall (number, a0, a1, a2, a3, a4, a5); +} +#else long int syscall (long int number, ...) { @@ -33,11 +57,6 @@ syscall (long int number, ...) long int a5 = va_arg (args, long int); va_end (args); - long int r = INTERNAL_SYSCALL_NCS_CALL (number, a0, a1, a2, a3, a4, a5); - if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (r))) - { - __set_errno (-r); - return -1; - } - return r; + return __syscall (number, a0, a1, a2, a3, a4, a5); } +#endif -- 2.40.0