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