tst-tls5.c 1.1 KB

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