@@ -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 \
@@ -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 ());
+}
@@ -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
new file mode 100644
@@ -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>
@@ -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
@@ -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)