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