tst-tls14.c 1.0 KB

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