aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorSachin Monga <smonga@linux.ibm.com>2023-05-10 13:59:21 -0400
committerRajalakshmi Srinivasaraghavan <rajis@linux.ibm.com>2023-05-10 13:59:48 -0500
commit1a57ab0c923f269d1d7c29dfe4634c0ae66d69ac (patch)
treea99cd546a6a7948f9b937d62473c3d0928547f57 /misc
parentf0dbe112f532be2101bb392f67f9f164cade25b0 (diff)
downloadglibc-1a57ab0c923f269d1d7c29dfe4634c0ae66d69ac.zip
glibc-1a57ab0c923f269d1d7c29dfe4634c0ae66d69ac.tar.gz
glibc-1a57ab0c923f269d1d7c29dfe4634c0ae66d69ac.tar.bz2
Added Redirects to longdouble error functions [BZ #29033]
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>
Diffstat (limited to 'misc')
-rw-r--r--misc/Makefile2
-rw-r--r--misc/bits/error-ldbl.h45
-rw-r--r--misc/sys/cdefs.h3
-rw-r--r--misc/tst-ldbl-errorfptr.c87
4 files changed, 135 insertions, 2 deletions
diff --git a/misc/Makefile b/misc/Makefile
index 1a09f77..9f42321 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 599a7d6..bbc4956 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 9a07e29..393d909 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 0000000..155932a
--- /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>