tst-tls14.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Check alignment of TLS variable. */
  2. #include <dlfcn.h>
  3. #include <stdint.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <tls.h>
  7. #if USE_TLS && HAVE___THREAD
  8. #define AL 4096
  9. struct foo
  10. {
  11. int i;
  12. } __attribute ((aligned (AL)));
  13. static __thread struct foo f;
  14. static struct foo g;
  15. extern int in_dso1 (void);
  16. static int
  17. do_test (void)
  18. {
  19. int result = 0;
  20. int fail = (((uintptr_t) &f) & (AL - 1)) != 0;
  21. printf ("&f = %p %s\n", &f, fail ? "FAIL" : "OK");
  22. result |= fail;
  23. fail = (((uintptr_t) &g) & (AL - 1)) != 0;
  24. printf ("&g = %p %s\n", &g, fail ? "FAIL" : "OK");
  25. result |= fail;
  26. result |= in_dso1 ();
  27. void *h = dlopen ("tst-tlsmod14b.so", RTLD_LAZY);
  28. if (h == NULL)
  29. {
  30. printf ("cannot open tst-tlsmod14b.so: %m\n");
  31. exit (1);
  32. }
  33. int (*fp) (void) = (int (*) (void)) dlsym (h, "in_dso2");
  34. if (fp == NULL)
  35. {
  36. puts ("cannot find in_dso2");
  37. exit (1);
  38. }
  39. result |= fp ();
  40. return result;
  41. }
  42. #define TEST_FUNCTION do_test ()
  43. #else
  44. #define TEST_FUNCTION 0
  45. #endif
  46. #include "../test-skeleton.c"