public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Added Redirects to longdouble error functions [BZ #29033]
@ 2023-04-17 11:04 Sachin Monga
  2023-04-17 11:04 ` [PATCH v6] " Sachin Monga
  0 siblings, 1 reply; 15+ messages in thread
From: Sachin Monga @ 2023-04-17 11:04 UTC (permalink / raw)
  To: libc-alpha; +Cc: Sachin Monga

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 <smonga@linux.ibm.com>
---
 misc/Makefile                               |  2 +-
 misc/bits/error-ldbl.h                      | 45 ++++++++++
 misc/sys/cdefs.h                            |  3 +-
 misc/tst-ldbl-errorfptr.c                   | 93 +++++++++++++++++++++
 sysdeps/ieee754/ldbl-128ibm-compat/Makefile |  2 +
 sysdeps/ieee754/ldbl-opt/Makefile           |  4 +
 6 files changed, 147 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 <bits/error-ldbl.h> directly; use <error.h> 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 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..e11575b6a5
--- /dev/null
+++ b/misc/tst-ldbl-errorfptr.c
@@ -0,0 +1,93 @@
+/* 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
+   <https://www.gnu.org/licenses/>.  */
+
+#include <err.h>
+#include <errno.h>
+#include <error.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+#include <sys/cdefs.h>
+
+#include <support/capture_subprocess.h>
+#include <support/check.h>
+#include <support/xdlfcn.h>
+
+#define NLDBL_SYMBOL2(alias) __ASMNAME (#alias)
+#define NLDBL_SYMBOL(alias) NLDBL_SYMBOL2 (__nldbl_##alias)
+#define IEEE_LONG_DOUBLE(alias) __ASMNAME ("__" #alias "ieee128")
+#define NO_LONG_DOUBLE(alias) NLDBL_SYMBOL (alias)
+#define DEFAULT_SYMBOL(alias) NLDBL_SYMBOL2 (alias)
+
+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;
+#if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
+  error_sym = (char *) IEEE_LONG_DOUBLE(error);
+  error_sym_at_line = (char *) IEEE_LONG_DOUBLE(error_at_line);
+#elif defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
+  error_sym = (char *) NO_LONG_DOUBLE(error);
+  error_sym_at_line = (char *) NO_LONG_DOUBLE(error_at_line);
+#else
+  error_sym = (char *) DEFAULT_SYMBOL(error);
+  error_sym_at_line = (char *) DEFAULT_SYMBOL(error_at_line);
+#endif
+  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 <support/test-driver.c>
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)
-- 
2.37.2


^ permalink raw reply	[flat|nested] 15+ messages in thread
* [PATCH] Added Redirects to longdouble error functions [BZ #29033]
@ 2023-05-09  5:01 Sachin Monga
  0 siblings, 0 replies; 15+ messages in thread
From: Sachin Monga @ 2023-05-09  5:01 UTC (permalink / raw)
  To: libc-alpha; +Cc: Sachin Monga, Manjul Mohan

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 <smonga@linux.ibm.com>
Signed-off-by: Manjul Mohan <manjul@linux.vnet.ibm.com>
---
 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 <bits/error-ldbl.h> directly; use <error.h> 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
+   <https://www.gnu.org/licenses/>.  */
+
+#include <err.h>
+#include <errno.h>
+#include <error.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+#include <sys/cdefs.h>
+
+#include <support/capture_subprocess.h>
+#include <support/check.h>
+#include <support/xdlfcn.h>
+
+#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 <support/test-driver.c>
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
 
-- 
2.31.1


^ permalink raw reply	[flat|nested] 15+ messages in thread
* [PATCH] Added Redirects to longdouble error functions [BZ #29033]
@ 2023-04-19 18:42 Sachin Monga
  2023-05-02 13:18 ` Rajalakshmi Srinivasaraghavan
  0 siblings, 1 reply; 15+ messages in thread
From: Sachin Monga @ 2023-04-19 18:42 UTC (permalink / raw)
  To: libc-alpha; +Cc: Sachin Monga

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 <smonga@linux.ibm.com>
---
 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 +
 6 files changed, 141 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 <bits/error-ldbl.h> directly; use <error.h> 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 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..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
+   <https://www.gnu.org/licenses/>.  */
+
+#include <err.h>
+#include <errno.h>
+#include <error.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+#include <sys/cdefs.h>
+
+#include <support/capture_subprocess.h>
+#include <support/check.h>
+#include <support/xdlfcn.h>
+
+#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 <support/test-driver.c>
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)
-- 
2.37.2


^ permalink raw reply	[flat|nested] 15+ messages in thread
* [PATCH] Added Redirects to longdouble error functions [BZ #29033]
@ 2023-04-13 17:48 Sachin Monga
  2023-04-14 13:25 ` Sachin Monga
  0 siblings, 1 reply; 15+ messages in thread
From: Sachin Monga @ 2023-04-13 17:48 UTC (permalink / raw)
  To: libc-alpha; +Cc: Sachin Monga

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 <smonga@linux.ibm.com>
---
 misc/Makefile                               |  2 +-
 misc/bits/error-ldbl.h                      | 45 ++++++++++
 misc/sys/cdefs.h                            |  3 +-
 misc/tst-ldbl-errorfptr.c                   | 91 +++++++++++++++++++++
 sysdeps/ieee754/ldbl-128ibm-compat/Makefile |  2 +
 sysdeps/ieee754/ldbl-opt/Makefile           |  4 +
 6 files changed, 145 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 <bits/error-ldbl.h> directly; use <error.h> 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 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..67b50c687f
--- /dev/null
+++ b/misc/tst-ldbl-errorfptr.c
@@ -0,0 +1,91 @@
+/* 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
+   <https://www.gnu.org/licenses/>.  */
+
+#include <err.h>
+#include <errno.h>
+#include <error.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+#include <sys/cdefs.h>
+
+#include <support/capture_subprocess.h>
+#include <support/check.h>
+#include <support/xdlfcn.h>
+
+#define NLDBL_SYMBOL2(alias) __ASMNAME (#alias)
+#define NLDBL_SYMBOL(alias) NLDBL_SYMBOL2 (__nldbl_##alias)
+#define IEEE_LONG_DOUBLE(alias) __ASMNAME ("__" #alias "ieee128")
+#define NO_LONG_DOUBLE(alias) NLDBL_SYMBOL (alias)
+
+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;
+#if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
+  error_sym = (char *) IEEE_LONG_DOUBLE(error);
+  error_sym_at_line = (char *) IEEE_LONG_DOUBLE(error_at_line);
+#elif defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
+  error_sym = (char *) NO_LONG_DOUBLE(error);
+  error_sym_at_line = (char *) NO_LONG_DOUBLE(error_at_line);
+#else
+  FAIL_EXIT1 ("test case error");
+#endif
+  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 <support/test-driver.c>
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)
-- 
2.37.2


^ permalink raw reply	[flat|nested] 15+ messages in thread
* [PATCH] Added Redirects to longdouble error functions [BZ #29033]
@ 2023-03-27  6:27 Sachin Monga
  0 siblings, 0 replies; 15+ messages in thread
From: Sachin Monga @ 2023-03-27  6:27 UTC (permalink / raw)
  To: libc-alpha; +Cc: Sachin Monga

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 <smonga@linux.ibm.com>
---
 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 <bits/error-ldbl.h> directly; use <error.h> 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.
+   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
+   <https://www.gnu.org/licenses/>.  */
+
+#include <err.h>
+#include <errno.h>
+#include <error.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+
+#include <support/capture_subprocess.h>
+#include <support/check.h>
+
+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(int ver) {
+  if(ver)
+    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;
+}
+
+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")))
+    {
+      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");
+
+  /* Map the function pointers to appropriate redirected symbols */
+  error_func_t fp;
+  fp = get_error_func(0);
+  if (fp != dlsym(RTLD_DEFAULT, exp))
+    {
+      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 <support/test-driver.c>
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)
-- 
2.37.2


^ permalink raw reply	[flat|nested] 15+ messages in thread
* [PATCH] Added Redirects to longdouble error functions [BZ #29033]
@ 2023-03-04 17:45 Sachin Monga
  2023-03-14 16:41 ` Paul E Murphy
  0 siblings, 1 reply; 15+ messages in thread
From: Sachin Monga @ 2023-03-04 17:45 UTC (permalink / raw)
  To: libc-alpha; +Cc: Sachin Monga

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 <smonga@linux.ibm.com>
---
 misc/Makefile                               |   2 +-
 misc/bits/error-ldbl.h                      |  53 ++++++++-
 misc/sys/cdefs.h                            |   3 +-
 misc/tst-ldbl-errorfptr.c                   | 114 ++++++++++++++++++++
 sysdeps/ieee754/ldbl-128ibm-compat/Makefile |   3 +
 sysdeps/ieee754/ldbl-opt/Makefile           |   5 +
 6 files changed, 176 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 <bits/error-ldbl.h> directly; use <error.h> 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..4896694fb9
--- /dev/null
+++ b/misc/tst-ldbl-errorfptr.c
@@ -0,0 +1,114 @@
+/* Test for the long double conversions in error* functions
+   when they are returned as function pointer.
+   Copyright (C) 2018-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
+   <https://www.gnu.org/licenses/>.  */
+
+#include <err.h>
+#include <errno.h>
+#include <error.h>
+#include <stdarg.h>
+#include <string.h>
+
+#include <support/capture_subprocess.h>
+#include <support/check.h>
+
+struct tests
+{
+  void *callback;
+  const char *expected;
+};
+
+va_list args;
+
+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
+get_error_func(void) {
+  return &error;
+}
+
+error_at_line_func_t
+get_error_at_line_func(void) {
+  return &error_at_line;
+}
+
+static void
+callback_error (void *closure)
+{
+  errno = 0;
+  error_func_t fp;
+  fp = get_error_func();
+  fp (0, 0, "%Lf", (long double) -1);
+}
+
+static void
+callback_error_at_line (void *closure)
+{
+  errno = 0;
+  error_at_line_func_t fpat;
+  fpat = get_error_at_line_func();
+  fpat (0, 0, "", 0, "%Lf", (long double) -1);
+}
+
+static void
+do_one_test (void *callback, const char *expected, ...)
+{
+  struct support_capture_subprocess result;
+
+  va_start (args, expected);
+
+  /* Call 'callback', which fills in the output and error buffers.  */
+  result = support_capture_subprocess (callback, NULL);
+
+  /* Filter out the name of the program (which should always end with
+     -errorfptr), so that the test case can be reused by ldbl-opt and
+     ldbl-128ibm-compat.  */
+  const char *needle = "-errorfptr:";
+  char *message;
+  message = strstr (result.err.buffer, needle);
+  printf("\nresult.err.buffer=%s",result.err.buffer);
+  if (message == NULL)
+    FAIL_EXIT1 ("test case error");
+  message += strlen (needle);
+
+  /* Verify that the output message is as expected.  */
+  TEST_COMPARE_STRING (message, expected);
+
+  va_end (args);
+}
+
+static int
+do_test (void)
+{
+  /* Test if error and error_at_line are returned as function pointers
+   * to the callback functions (BZ #29033). */
+  struct tests tests[] = {
+    { &callback_error, " -1.000000\n" },
+    { &callback_error_at_line, ":0: -1.000000\n" }
+  };
+
+  for (int i = 0; i < sizeof (tests) / sizeof (tests[0]); i++)
+    {
+      do_one_test (tests[i].callback, tests[i].expected, (long double) -1);
+    }
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/Makefile b/sysdeps/ieee754/ldbl-128ibm-compat/Makefile
index 67d476383a..6aa73d2798 100644
--- a/sysdeps/ieee754/ldbl-128ibm-compat/Makefile
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/Makefile
@@ -252,6 +252,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-ibm128-errorfptr tst-ieee128-errorfptr
 
 $(objpfx)tst-ibm128-%.c: tst-ldbl-%.c
 	cp $< $@
@@ -262,10 +263,12 @@ $(objpfx)tst-ieee128-%.c: tst-ldbl-%.c
 CFLAGS-tst-ibm128-warn.c += -mabi=ibmlongdouble -Wno-psabi
 CFLAGS-tst-ibm128-error.c += -mabi=ibmlongdouble -Wno-psabi
 CFLAGS-tst-ibm128-efgcvt.c += -mabi=ibmlongdouble -Wno-psabi
+CFLAGS-tst-ibm128-errorfptr.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 1d01846476..1baf065654 100644
--- a/sysdeps/ieee754/ldbl-opt/Makefile
+++ b/sysdeps/ieee754/ldbl-opt/Makefile
@@ -211,6 +211,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 $< $@
@@ -218,6 +219,10 @@ $(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
-- 
2.37.2


^ permalink raw reply	[flat|nested] 15+ messages in thread
* [PATCH] Added Redirects to longdouble error functions [BZ #29033]
@ 2023-02-20  7:17 Sachin Monga
  2023-02-21 10:16 ` Florian Weimer
  0 siblings, 1 reply; 15+ messages in thread
From: Sachin Monga @ 2023-02-20  7:17 UTC (permalink / raw)
  To: libc-alpha; +Cc: Sachin Monga

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 <smonga@linux.ibm.com>
---
 misc/bits/error-ldbl.h | 53 ++++++++++++++++++++++++++++++++++++++++--
 misc/sys/cdefs.h       |  3 ++-
 2 files changed, 53 insertions(+), 3 deletions(-)

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 <bits/error-ldbl.h> directly; use <error.h> 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 66d6702123..37b20fe3d6 100644
--- a/misc/sys/cdefs.h
+++ b/misc/sys/cdefs.h
@@ -567,6 +567,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) \
@@ -584,7 +586,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
-- 
2.37.2


^ permalink raw reply	[flat|nested] 15+ messages in thread
* [PATCH] Added Redirects to longdouble error functions [BZ #29033]
@ 2023-02-09 17:45 Sachin Monga
  2023-02-13 23:07 ` Paul E Murphy
  0 siblings, 1 reply; 15+ messages in thread
From: Sachin Monga @ 2023-02-09 17:45 UTC (permalink / raw)
  To: libc-alpha; +Cc: Sachin Monga

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 <smonga@linux.ibm.com>
---
 misc/bits/error-ldbl.h | 53 ++++++++++++++++++++++++++++++++++++++++--
 misc/sys/cdefs.h       |  6 +++++
 2 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/misc/bits/error-ldbl.h b/misc/bits/error-ldbl.h
index 599a7d6e06..73ecbe7a10 100644
--- a/misc/bits/error-ldbl.h
+++ b/misc/bits/error-ldbl.h
@@ -20,5 +20,54 @@
 # error "Never include <bits/error-ldbl.h> directly; use <error.h> instead."
 #endif
 
-__LDBL_REDIR_DECL (error)
-__LDBL_REDIR_DECL (error_at_line)
+
+__LDBL_REDIRECT (__error_alias, (int __status, int __errnum,
+					const char *__format, ...),
+			error)
+  __attribute__ ((__format__ (__printf__, 3, 4)));
+__LDBL_REDIRECT (__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 ());
+}
+
+
+__LDBL_REDIRECT (__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)));
+__LDBL_REDIRECT (__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 66d6702123..34fdd3c24a 100644
--- a/misc/sys/cdefs.h
+++ b/misc/sys/cdefs.h
@@ -245,6 +245,7 @@
 #if (defined __GNUC__ && __GNUC__ >= 2) || (__clang_major__ >= 4)
 
 # define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
+
 # ifdef __cplusplus
 #  define __REDIRECT_NTH(name, proto, alias) \
      name proto __THROW __asm__ (__ASMNAME (#alias))
@@ -567,6 +568,8 @@
 #  define __LDBL_REDIR(name, proto) ... unused__ldbl_redir
 #  define __LDBL_REDIR_DECL(name) \
   extern __typeof (name) name __asm (__ASMNAME ("__" #name "ieee128"));
+#  define __LDBL_REDIRECT(name, proto, alias) \
+  extern void name proto __asm (__ASMNAME ("__" #alias "ieee128"))
 
 /* Alias name defined automatically, with leading underscores.  */
 #  define __LDBL_REDIR2_DECL(name) \
@@ -605,6 +608,8 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf
   extern __typeof (name) name __asm (__ASMNAME (#alias));
 #  define __LDBL_REDIR_DECL(name) \
   extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name));
+#  define __LDBL_REDIRECT(name, proto, alias) \
+  extern void name proto __asm (__ASMNAME ("__nldbl_" #alias));
 #  define __REDIRECT_LDBL(name, proto, alias) \
   __LDBL_REDIR1 (name, proto, __nldbl_##alias)
 #  define __REDIRECT_NTH_LDBL(name, proto, alias) \
@@ -619,6 +624,7 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf
 # define __LDBL_REDIR_NTH(name, proto) name proto __THROW
 # define __LDBL_REDIR2_DECL(name)
 # define __LDBL_REDIR_DECL(name)
+# define __LDBL_REDIRECT(name, proto, alias)
 # ifdef __REDIRECT
 #  define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
 #  define __REDIRECT_NTH_LDBL(name, proto, alias) \
-- 
2.37.2


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-05-09  5:01 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-17 11:04 [PATCH] Added Redirects to longdouble error functions [BZ #29033] Sachin Monga
2023-04-17 11:04 ` [PATCH v6] " Sachin Monga
2023-04-18 22:13   ` Paul E Murphy
  -- strict thread matches above, loose matches on Subject: below --
2023-05-09  5:01 [PATCH] " Sachin Monga
2023-04-19 18:42 Sachin Monga
2023-05-02 13:18 ` Rajalakshmi Srinivasaraghavan
2023-04-13 17:48 Sachin Monga
2023-04-14 13:25 ` Sachin Monga
2023-03-27  6:27 Sachin Monga
2023-03-04 17:45 Sachin Monga
2023-03-14 16:41 ` Paul E Murphy
2023-02-20  7:17 Sachin Monga
2023-02-21 10:16 ` Florian Weimer
2023-02-09 17:45 Sachin Monga
2023-02-13 23:07 ` Paul E Murphy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).