tststatic5.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* GLRO(dl_pagesize) initialization DSO test with a static executable.
  2. Copyright (C) 2013-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <dlfcn.h>
  16. #include <stddef.h>
  17. #include <stdio.h>
  18. #include <unistd.h>
  19. /* Check that the same page size is reported both directly and by a DSO
  20. mapped from a static executable.
  21. On targets that support different page sizes, the kernel communicates
  22. the size currently in use via the auxiliary vector. The auxiliary
  23. vector and HWCAP/HWCAP2 bits are copied across the static dlopen
  24. boundary in __rtld_static_init. */
  25. static int
  26. do_test (void)
  27. {
  28. int pagesize = getpagesize ();
  29. int (*my_getpagesize) (void);
  30. int my_pagesize;
  31. void *handle;
  32. /* Try to map a module. */
  33. handle = dlopen ("modstatic5.so", RTLD_LAZY | RTLD_LOCAL);
  34. if (handle == NULL)
  35. {
  36. printf ("dlopen (modstatic5.so): %s\n", dlerror ());
  37. return 1;
  38. }
  39. /* Get at its symbol. */
  40. my_getpagesize = dlsym (handle, "my_getpagesize");
  41. if (my_getpagesize == NULL)
  42. {
  43. printf ("dlsym (my_getpagesize): %s\n", dlerror ());
  44. return 1;
  45. }
  46. /* Make sure the page size reported is the same either way. */
  47. my_pagesize = my_getpagesize ();
  48. if (my_pagesize != pagesize)
  49. {
  50. printf ("my_getpagesize: got %i, expected %i\n", my_pagesize, pagesize);
  51. return 1;
  52. }
  53. /* All done, clean up. */
  54. my_getpagesize = NULL;
  55. dlclose (handle);
  56. return 0;
  57. }
  58. #define TEST_FUNCTION do_test ()
  59. #include "../test-skeleton.c"