From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) by sourceware.org (Postfix) with ESMTPS id 2EAA03858CDA for ; Mon, 27 Mar 2023 13:38:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2EAA03858CDA Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oo1-xc33.google.com with SMTP id w13-20020a4aca0d000000b0053b8aa32089so1326918ooq.5 for ; Mon, 27 Mar 2023 06:38:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679924292; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=kBEvpDiz0yMHtVS8xx1p6uRPl253xLx59aOx5g2t3ZM=; b=CUc1PPgazBeXKXMHQRJ67jcpNALsCLRN08mdgpVTYBielDytmCjvDLRHuEwIbChENW O7mFP2EN5o0DZHGRuKu3FCCpY+5UpsTqvsaTWLMglCfcHiPn7+49zOdfp++0eRDi/Dzp VLQ72Sxl8kt9pjUYi9G4fAB7VTJUsREA10EYoh+YkEKy9frqDns5jYU8uCRZkVur2e/6 4Hdi02CZMzeLkp8ZH4UGpfx7+uSJ0MdXimHNR0r3nwsPpWWwCq4VwSdZ6TbbVaR3WhpX p0pK9CxV7uMR9Oncmp2xxOe6CALEEV1nrby8aC1rwUvs1kFselhXcJ6XPd5M5dYJCwn2 C25w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679924292; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kBEvpDiz0yMHtVS8xx1p6uRPl253xLx59aOx5g2t3ZM=; b=lB8C/YHHDSBGZZdWdkJHLfxmIwxxA9/PP9tjE6LB5IV5QMI6TlsQk16Fs1vB76VtJw vyftoxueS6sn9lGDoJYHPRln+5y9vd0n4QWMrQHCOtRMnXCWvVFVEd1Bt8GcREIlQrHb k4hv4batjjm4T8Rradwgc56GgeWI3EoDrq51q1Dvfc2+X/PT7JpWcp/tGEMQOO6NHFnB fvR0Yj9WJa8EvBbITJ0Bpon2OaT25dPhrSsT67VzJ/twnEMTc5vVKinQBdvpSuSoJBGM 4gJh/LjHhV/t2Mt2hWyW+xqPY+F80+afHmLTdFzZCKhzN/tcJVbxykWgqnNTYHmMtOn8 RGTQ== X-Gm-Message-State: AO0yUKW/4STxiqlLDGY1EKgyHXXDEaO2vAuGurOZzSN3nJHvdCYA7nai gKORLXnvvLdpeD4MXdejtrfDVL0I2fNkw/ZsIPPqvw== X-Google-Smtp-Source: AK7set9Wi8FZ5DpqO/8o5YZeSG/ueIZCVABenTIj43Bkvudqspc4fZKhiBVfuOE1HDqPY6bZq01wPg== X-Received: by 2002:a4a:4f94:0:b0:517:752d:678a with SMTP id c142-20020a4a4f94000000b00517752d678amr6145196oob.1.1679924291689; Mon, 27 Mar 2023 06:38:11 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c1:60f9:9d7f:7b90:a6ae:401d? ([2804:1b3:a7c1:60f9:9d7f:7b90:a6ae:401d]) by smtp.gmail.com with ESMTPSA id y45-20020a4a9830000000b0053bb063121asm3315549ooi.9.2023.03.27.06.38.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 Mar 2023 06:38:11 -0700 (PDT) Message-ID: <9db30781-eefc-b122-50d6-1170a1412df1@linaro.org> Date: Mon, 27 Mar 2023 10:38:09 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH v4 v4] Added Redirects to longdouble error functions [BZ #29033] Content-Language: en-US To: libc-alpha@sourceware.org, Sachin Monga References: <20230327062748.2207905-1-smonga@linux.ibm.com> <20230327062748.2207905-2-smonga@linux.ibm.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <20230327062748.2207905-2-smonga@linux.ibm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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: On 27/03/23 03:27, Sachin Monga via Libc-alpha wrote: > 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 Besides the regression, there are some other issues on testcase where it does not follow glibc code style and conventions [1]. [1] https://sourceware.org/glibc/wiki/Style_and_Conventions > --- > misc/Makefile | 2 +- > misc/bits/error-ldbl.h | 53 ++++++++- > misc/sys/cdefs.h | 3 +- > misc/tst-ldbl-errorfptr.c | 117 ++++++++++++++++++++ > sysdeps/ieee754/ldbl-128ibm-compat/Makefile | 2 + > sysdeps/ieee754/ldbl-opt/Makefile | 4 + > 6 files changed, 177 insertions(+), 4 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..638e030c96 100644 > --- a/misc/bits/error-ldbl.h > +++ b/misc/bits/error-ldbl.h > @@ -20,5 +20,54 @@ > # error "Never include directly; use instead." > #endif > > -__LDBL_REDIR_DECL (error) > -__LDBL_REDIR_DECL (error_at_line) > + > +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 ()); > +} > diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h > index 23ec0ebd2a..285191482a 100644 > --- a/misc/sys/cdefs.h > +++ b/misc/sys/cdefs.h > @@ -569,6 +569,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) \ > @@ -586,7 +588,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..96b30cd83b > --- /dev/null > +++ b/misc/tst-ldbl-errorfptr.c > @@ -0,0 +1,117 @@ > +/* Test for the long double redirections in error* functions > + when they are returned as function pointer BZ #29033. > + Copyright (C) 2018-2023 Free Software Foundation, Inc. Copyright should be only 2023. > + 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 > + > +typedef void (*error_func_t) (int ,int ,const char* ,...); > +typedef void (*error_at_line_func_t) (int ,int ,const char* > + ,unsigned int ,const char* ,...); Syntax seems off here, I think the space should be after comma: typedef void (*error_func_t) (int, int, const char *, ...); > + > +error_func_t > +__attribute__((noinline)) > +get_error_func(int ver) { Space after function name and bracket should be in a new line. > + if(ver) Space after 'if' and no implicit check (use 'ver != 0'). > + return &__error_alias; > + > + return &__error_noreturn; > +} > + > +error_at_line_func_t > +__attribute__((noinline)) > +get_error_at_line_func(int ver) { > + if(ver) > + return &__error_at_line_alias; > + > + return &__error_at_line_noreturn; > +} > + Same as before. > +static int > +do_test (int argc, char *argv[]) > +{ > + /* Trim needle from testcase name */ > + const char *needle = "tst-"; > + char *message; > + message = strstr (argv[0], needle); > + if (message == NULL) > + FAIL_EXIT1 ("test case error - needle not found"); > + message += strlen (needle); > + > + /* Create buffer with max length symbol + 1 */ > + char exp[15]; > + char exp_at_line[23]; > + /* Prepare the symbol names */ > + if(!strncmp (message, "ldbl", strlen("ldbl")) || > + !strncmp (message, "ieee128", strlen("ieee128"))) No implicit check (use 'strncmp != 0'). > + { > + strcpy(exp, "__errorieee128"); > + strcpy (exp_at_line, "__error_at_lineieee128"); > + } > + else if(!strncmp (message, "nldbl", strlen("nldbl"))) > + { > + strcpy (exp, "__nldbl_error"); > + strcpy (exp_at_line, "__nldbl_error_at_line"); > + } > + else > + FAIL_EXIT1 ("test case error"); Just use: const char *exp = NULL; const char *exp_at_line = NULL; if (strncmp (message, "ldbl", strlen ("ldbl")) == 0 || strncmp (message, "ieee128", strlen ("ieee128")) == 0) { exp = "__errorieee128"; exp_at_line = "__error_at_lineieee128"; } else if (strncmp (message, "nldbl", strlen ("nldbl")) == 0) { exp = "__nldbl_error"; exp_at_line = "__nldbl_error_at_line"; } TEST_VERIFY (exp != NULL && exp_at_line != NULL); > + > + /* Map the function pointers to appropriate redirected symbols */ > + error_func_t fp; > + fp = get_error_func(0); > + if (fp != dlsym(RTLD_DEFAULT, exp)) Use xdlsym (since the function should be defined). > + { > + printf("\nFAIL fp=%p exp=%p\n",fp,exp); > + return 1; > + } > + > + fp = get_error_func(1); > + if (fp != dlsym(RTLD_DEFAULT, exp)) > + { > + printf("\nFAIL ver1 fp=%p exp=%p\n",fp,exp); > + return 1; > + } > + > + error_at_line_func_t fpat; > + fpat = get_error_at_line_func(0); > + if (fpat != dlsym(RTLD_DEFAULT, exp_at_line)) > + { > + printf("\nFAIL fp=%p exp_at_line=%p\n",fp,exp_at_line); > + return 1; > + } > + > + fpat = get_error_at_line_func(1); > + if (fpat != dlsym(RTLD_DEFAULT, exp_at_line)) > + { > + printf("\nFAIL ver1 fp=%p exp_at_line=%p\n",fp,exp_at_line); > + return 1; > + } > + > + return 0; > +} > + > +#define TEST_FUNCTION_ARGV do_test > +#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)