Add a test to check for duplicate definitions in the static library
[glibc.git] / misc / tst-ldbl-errorfptr.c
bloba94ab253f3f0b4ff3c6b426109c00168425f34f9
1 /* Test for the long double redirections in error* functions
2 when they are returned as function pointer BZ #29033.
3 Copyright (C) 2023-2024 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
20 #include <err.h>
21 #include <errno.h>
22 #include <error.h>
23 #include <stdarg.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #include <dlfcn.h>
27 #include <sys/cdefs.h>
29 #include <support/capture_subprocess.h>
30 #include <support/check.h>
31 #include <support/xdlfcn.h>
33 #if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
34 # define LDBL_NAME(alias) "__" #alias "ieee128"
35 #elif defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
36 # define LDBL_NAME(alias) "__nldbl_" #alias
37 #else
38 # define LDBL_NAME(alias) #alias
39 #endif
41 typedef void (*error_func_t) (int, int, const char*, ...);
42 typedef void (*error_at_line_func_t) (int, int, const char*,
43 unsigned int, const char*, ...);
45 error_func_t
46 __attribute__ ((noinline))
47 get_error_func (void) {
48 return &error;
51 error_at_line_func_t
52 __attribute__ ((noinline))
53 get_error_at_line_func (void) {
54 return &error_at_line;
57 static int
58 do_test (void)
60 /* Prepare the symbol names as per long double standards */
61 char *error_sym = NULL;
62 char *error_sym_at_line = NULL;
63 error_sym = (char *) LDBL_NAME(error);
64 error_sym_at_line = (char *) LDBL_NAME(error_at_line);
65 TEST_VERIFY (error_sym != NULL && error_sym_at_line != NULL);
66 /* Map the function pointers to appropriate redirected error symbols */
67 error_func_t fp;
68 fp = get_error_func ();
69 if (fp != xdlsym (RTLD_DEFAULT, error_sym))
71 printf ("FAIL: fp=%p error_sym=%p\n", fp, error_sym);
72 return 1;
75 error_at_line_func_t fpat;
76 fpat = get_error_at_line_func ();
77 if (fpat != xdlsym (RTLD_DEFAULT, error_sym_at_line))
79 printf ("FAIL: fpat=%p error_sym_at_line=%p\n",
80 fpat, error_sym_at_line);
81 return 1;
84 return 0;
87 #include <support/test-driver.c>