tst-ldbl-errorfptr.c 2.6 KB

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