tst-tls5.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <dlfcn.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <tls.h>
  5. #define TEST_FUNCTION do_test ()
  6. static int
  7. do_test (void)
  8. {
  9. #ifdef USE_TLS
  10. static const char modname[] = "tst-tlsmod2.so";
  11. int result = 0;
  12. int *foop;
  13. int *foop2;
  14. int (*fp) (int, int *);
  15. void *h;
  16. h = dlopen (modname, RTLD_LAZY);
  17. if (h == NULL)
  18. {
  19. printf ("cannot open '%s': %s\n", modname, dlerror ());
  20. exit (1);
  21. }
  22. foop = dlsym (h, "foo");
  23. if (foop == NULL)
  24. {
  25. printf ("cannot get symbol 'foo': %s\n", dlerror ());
  26. exit (1);
  27. }
  28. *foop = 42;
  29. fp = dlsym (h, "in_dso");
  30. if (fp == NULL)
  31. {
  32. printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
  33. exit (1);
  34. }
  35. result |= fp (42, foop);
  36. foop2 = dlsym (h, "foo");
  37. if (foop2 == NULL)
  38. {
  39. printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
  40. exit (1);
  41. }
  42. if (foop != foop2)
  43. {
  44. puts ("address of 'foo' different the second time");
  45. result = 1;
  46. }
  47. else if (*foop != 16)
  48. {
  49. puts ("foo != 16");
  50. result = 1;
  51. }
  52. dlclose (h);
  53. return result;
  54. #else
  55. return 0;
  56. #endif
  57. }
  58. #include "../test-skeleton.c"