From patchwork Tue May 9 05:01:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sachin Monga X-Patchwork-Id: 68936 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C43A13858438 for ; Tue, 9 May 2023 05:01:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C43A13858438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683608515; bh=rR61DnpIpjbvDUb1xB7FE/KGPi2bosr23rpAPahoqHs=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=qkUjsHVUmT10BEe8ADf1cBJQ6vShzL0bzSWYS5kPp5kWU8Z9vM7eDFnHaKFaBGhWK gz2HN4Co3Sib70CidcgbSbH3xGJMQSxRhpHarVXpesEdRPJugNZ/4pSLPvs9hVWeDl kQP+nHsZvt5MeYGmE3t1nY/22fioZ6ypWxr2cRjc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 449ED3858C50 for ; Tue, 9 May 2023 05:01:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 449ED3858C50 Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3494lgxV014152 for ; Tue, 9 May 2023 05:01:30 GMT Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qfffagaxg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 09 May 2023 05:01:29 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3494ZkRY032456 for ; Tue, 9 May 2023 05:01:27 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma05fra.de.ibm.com (PPS) with ESMTPS id 3qf7mhg4jr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 09 May 2023 05:01:27 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34951N4v31130118 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 9 May 2023 05:01:23 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6036B20067; Tue, 9 May 2023 05:01:23 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9E45B2004F; Tue, 9 May 2023 05:01:22 +0000 (GMT) Received: from ltcd97-lp3.. (unknown [9.40.194.171]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 9 May 2023 05:01:22 +0000 (GMT) To: libc-alpha@sourceware.org Cc: Sachin Monga , Manjul Mohan Subject: [PATCH] Added Redirects to longdouble error functions [BZ #29033] Date: Tue, 9 May 2023 01:01:19 -0400 Message-Id: <20230509050119.2837584-1-smonga@linux.ibm.com> X-Mailer: git-send-email 2.37.2 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: XuVQxpQNrQZLUVXx98ftn9KapIDsralx X-Proofpoint-ORIG-GUID: XuVQxpQNrQZLUVXx98ftn9KapIDsralx X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-09_02,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 mlxscore=0 malwarescore=0 phishscore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1011 spamscore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305090034 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sachin Monga via Libc-alpha From: Sachin Monga Reply-To: Sachin Monga Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This patch redirects the error functions to the appropriate longdouble variants which enables the compiler to optimize for the abi ieeelongdouble. Signed-off-by: Sachin Monga Signed-off-by: Manjul Mohan --- misc/Makefile | 2 +- misc/bits/error-ldbl.h | 45 +++++++++++ misc/sys/cdefs.h | 3 +- misc/tst-ldbl-errorfptr.c | 87 +++++++++++++++++++++ sysdeps/ieee754/ldbl-128ibm-compat/Makefile | 2 + sysdeps/ieee754/ldbl-opt/Makefile | 4 + sysdeps/powerpc/powerpc64/le/Makefile | 1 + 7 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 misc/tst-ldbl-errorfptr.c diff --git a/misc/Makefile b/misc/Makefile index 1a09f777fa..9f42321206 100644 --- a/misc/Makefile +++ b/misc/Makefile @@ -90,7 +90,7 @@ tests := tst-dirname tst-tsearch tst-fdset tst-mntent tst-hsearch \ tst-preadvwritev2 tst-preadvwritev64v2 tst-warn-wide \ tst-ldbl-warn tst-ldbl-error tst-dbl-efgcvt tst-ldbl-efgcvt \ tst-mntent-autofs tst-syscalls tst-mntent-escape tst-select \ - tst-ioctl + tst-ioctl tst-ldbl-errorfptr tests-time64 := \ tst-select-time64 \ diff --git a/misc/bits/error-ldbl.h b/misc/bits/error-ldbl.h index 599a7d6e06..bbc4956f68 100644 --- a/misc/bits/error-ldbl.h +++ b/misc/bits/error-ldbl.h @@ -20,5 +20,50 @@ # error "Never include directly; use instead." #endif +#if defined __extern_always_inline && defined __va_arg_pack +extern void __REDIRECT_LDBL (__error_alias, (int __status, int __errnum, + const char *__format, ...), error) + __attribute__ ((__format__ (__printf__, 3, 4))); +extern void __REDIRECT_LDBL (__error_noreturn, (int __status, int __errnum, + const char *__format, ...), error) + __attribute__ ((__noreturn__, __format__ (__printf__, 3, 4))); + + +/* If we know the function will never return make sure the compiler + realizes that, too. */ +__extern_always_inline void +error (int __status, int __errnum, const char *__format, ...) +{ + if (__builtin_constant_p (__status) && __status != 0) + __error_noreturn (__status, __errnum, __format, __va_arg_pack ()); + else + __error_alias (__status, __errnum, __format, __va_arg_pack ()); +} + + +extern void __REDIRECT_LDBL (__error_at_line_alias, (int __status, int __errnum, + const char *__fname, unsigned int __line, + const char *__format, ...), error_at_line) + __attribute__ ((__format__ (__printf__, 5, 6))); +extern void __REDIRECT_LDBL (__error_at_line_noreturn, (int __status, int __errnum, + const char *__fname, unsigned int __line, + const char *__format, ...), error_at_line) + __attribute__ ((__noreturn__, __format__ (__printf__, 5, 6))); + + +/* If we know the function will never return make sure the compiler + realizes that, too. */ +__extern_always_inline void +error_at_line (int __status, int __errnum, const char *__fname, + unsigned int __line, const char *__format, ...) +{ + if (__builtin_constant_p (__status) && __status != 0) + __error_at_line_noreturn (__status, __errnum, __fname, __line, __format, + __va_arg_pack ()); + else + __error_at_line_alias (__status, __errnum, __fname, __line, + __format, __va_arg_pack ()); +} +#endif __LDBL_REDIR_DECL (error) __LDBL_REDIR_DECL (error_at_line) diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h index 9a07e297a6..393d9091d9 100644 --- a/misc/sys/cdefs.h +++ b/misc/sys/cdefs.h @@ -576,6 +576,8 @@ # define __LDBL_REDIR(name, proto) ... unused__ldbl_redir # define __LDBL_REDIR_DECL(name) \ extern __typeof (name) name __asm (__ASMNAME ("__" #name "ieee128")); +# define __REDIRECT_LDBL(name, proto, alias) \ + name proto __asm (__ASMNAME ("__" #alias "ieee128")) /* Alias name defined automatically, with leading underscores. */ # define __LDBL_REDIR2_DECL(name) \ @@ -593,7 +595,6 @@ __LDBL_REDIR1_NTH (name, proto, __##alias##ieee128) /* Unused. */ -# define __REDIRECT_LDBL(name, proto, alias) ... unused__redirect_ldbl # define __LDBL_REDIR_NTH(name, proto) ... unused__ldbl_redir_nth # else diff --git a/misc/tst-ldbl-errorfptr.c b/misc/tst-ldbl-errorfptr.c new file mode 100644 index 0000000000..155932afe1 --- /dev/null +++ b/misc/tst-ldbl-errorfptr.c @@ -0,0 +1,87 @@ +/* Test for the long double redirections in error* functions + when they are returned as function pointer BZ #29033. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 +# define LDBL_NAME(alias) "__" #alias "ieee128" +#elif defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH +# define LDBL_NAME(alias) "__nldbl_" #alias +#else +# define LDBL_NAME(alias) #alias +#endif + +typedef void (*error_func_t) (int, int, const char*, ...); +typedef void (*error_at_line_func_t) (int, int, const char*, + unsigned int, const char*, ...); + +error_func_t +__attribute__ ((noinline)) +get_error_func (void) { + return &error; +} + +error_at_line_func_t +__attribute__ ((noinline)) +get_error_at_line_func (void) { + return &error_at_line; +} + +static int +do_test (void) +{ + /* Prepare the symbol names as per long double standards */ + char *error_sym = NULL; + char *error_sym_at_line = NULL; + error_sym = (char *) LDBL_NAME(error); + error_sym_at_line = (char *) LDBL_NAME(error_at_line); + TEST_VERIFY (error_sym != NULL && error_sym_at_line != NULL); + /* Map the function pointers to appropriate redirected error symbols */ + error_func_t fp; + fp = get_error_func (); + if (fp != xdlsym (RTLD_DEFAULT, error_sym)) + { + printf ("FAIL: fp=%p error_sym=%p\n", fp, error_sym); + return 1; + } + + error_at_line_func_t fpat; + fpat = get_error_at_line_func (); + if (fpat != xdlsym (RTLD_DEFAULT, error_sym_at_line)) + { + printf ("FAIL: fpat=%p error_sym_at_line=%p\n", + fpat, error_sym_at_line); + return 1; + } + + return 0; +} + +#include diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/Makefile b/sysdeps/ieee754/ldbl-128ibm-compat/Makefile index d4ec41bf99..42cca25a09 100644 --- a/sysdeps/ieee754/ldbl-128ibm-compat/Makefile +++ b/sysdeps/ieee754/ldbl-128ibm-compat/Makefile @@ -264,6 +264,7 @@ CFLAGS-ieee128-qefgcvt_r.c += -mabi=ieeelongdouble -Wno-psabi -mno-gnu-attribute tests-internal += tst-ibm128-warn tst-ieee128-warn tests-internal += tst-ibm128-error tst-ieee128-error tests-internal += tst-ibm128-efgcvt tst-ieee128-efgcvt +tests-internal += tst-ieee128-errorfptr $(objpfx)tst-ibm128-%.c: tst-ldbl-%.c cp $< $@ @@ -278,6 +279,7 @@ CFLAGS-tst-ibm128-efgcvt.c += -mabi=ibmlongdouble -Wno-psabi CFLAGS-tst-ieee128-warn.c += -mfloat128 -mabi=ieeelongdouble -Wno-psabi CFLAGS-tst-ieee128-error.c += -mfloat128 -mabi=ieeelongdouble -Wno-psabi CFLAGS-tst-ieee128-efgcvt.c += -mfloat128 -mabi=ieeelongdouble -Wno-psabi +CFLAGS-tst-ieee128-errorfptr.c += -mfloat128 -mabi=ieeelongdouble -Wno-psabi tests-container += test-syslog-ieee128 test-syslog-ibm128 CFLAGS-test-syslog-ieee128.c += -mfloat128 -mabi=ieeelongdouble -Wno-psabi diff --git a/sysdeps/ieee754/ldbl-opt/Makefile b/sysdeps/ieee754/ldbl-opt/Makefile index 5b72474aa4..22e778ad0e 100644 --- a/sysdeps/ieee754/ldbl-opt/Makefile +++ b/sysdeps/ieee754/ldbl-opt/Makefile @@ -215,6 +215,7 @@ endif ifeq ($(subdir), misc) tests-internal += tst-nldbl-warn tests-internal += tst-nldbl-error +tests-internal += tst-nldbl-errorfptr $(objpfx)tst-nldbl-warn.c: tst-ldbl-warn.c cp $< $@ @@ -222,8 +223,11 @@ $(objpfx)tst-nldbl-warn.c: tst-ldbl-warn.c $(objpfx)tst-nldbl-error.c: tst-ldbl-error.c cp $< $@ +$(objpfx)tst-nldbl-errorfptr.c: tst-ldbl-errorfptr.c + cp $< $@ CFLAGS-tst-nldbl-warn.c += -mlong-double-64 CFLAGS-tst-nldbl-error.c += -mlong-double-64 +CFLAGS-tst-nldbl-errorfptr.c += -mlong-double-64 endif ifeq ($(subdir), stdio-common) diff --git a/sysdeps/powerpc/powerpc64/le/Makefile b/sysdeps/powerpc/powerpc64/le/Makefile index 7c036b45fc..53644d50cc 100644 --- a/sysdeps/powerpc/powerpc64/le/Makefile +++ b/sysdeps/powerpc/powerpc64/le/Makefile @@ -104,6 +104,7 @@ ifeq ($(subdir),misc) $(foreach suf,$(all-object-suffixes),\ $(objpfx)tst-nldbl-warn$(suf) \ $(objpfx)tst-nldbl-error$(suf) \ + $(objpfx)tst-nldbl-errorfptr$(suf) \ ): sysdep-CFLAGS := $(filter-out -mabi=ieeelongdouble,$(sysdep-CFLAGS)) endif