tst-tls16.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <dlfcn.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. static int
  5. do_test (void)
  6. {
  7. void *h = dlopen ("tst-tlsmod16a.so", RTLD_LAZY | RTLD_GLOBAL);
  8. if (h == NULL)
  9. {
  10. puts ("unexpectedly failed to open tst-tlsmod16a.so");
  11. exit (1);
  12. }
  13. void *p = dlsym (h, "tlsvar");
  14. /* This dlopen should indeed fail, because tlsvar was assigned to
  15. dynamic TLS, and the new module requests it to be in static TLS.
  16. However, there's a possibility that dlopen succeeds if the
  17. variable is, for whatever reason, assigned to static TLS, or if
  18. the module fails to require static TLS, or even if TLS is not
  19. supported. */
  20. h = dlopen ("tst-tlsmod16b.so", RTLD_NOW | RTLD_GLOBAL);
  21. if (h == NULL)
  22. {
  23. return 0;
  24. }
  25. puts ("unexpectedly succeeded to open tst-tlsmod16b.so");
  26. void *(*fp) (void) = (void *(*) (void)) dlsym (h, "in_dso");
  27. if (fp == NULL)
  28. {
  29. puts ("cannot find in_dso");
  30. exit (1);
  31. }
  32. /* If the dlopen passes, at least make sure the address returned by
  33. dlsym is the same as that returned by the initial-exec access.
  34. If the variable was assigned to dynamic TLS during dlsym, this
  35. portion will fail. */
  36. if (fp () != p)
  37. {
  38. puts ("returned values do not match");
  39. exit (1);
  40. }
  41. return 0;
  42. }
  43. #define TEST_FUNCTION do_test ()
  44. #include "../test-skeleton.c"