chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.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 #include <tls.h>
8
9 #if HAVE___THREAD
10
11 # define AL 4096
12 struct foo
13 {
14   int i;
15 } __attribute ((aligned (AL)));
16
17 static __thread struct foo f;
18 static struct foo g;
19
20
21 extern int in_dso1 (void);
22
23
24 static int
25 do_test (void)
26 {
27   int result = 0;
28
29   int fail = (((uintptr_t) &f) & (AL - 1)) != 0;
30   printf ("&f = %p %s\n", &f, fail ? "FAIL" : "OK");
31   result |= fail;
32
33   fail = (((uintptr_t) &g) & (AL - 1)) != 0;
34   printf ("&g = %p %s\n", &g, fail ? "FAIL" : "OK");
35   result |= fail;
36
37   result |= in_dso1 ();
38
39   void *h = dlopen ("tst-tlsmod14b.so", RTLD_LAZY);
40   if (h == NULL)
41     {
42       printf ("cannot open tst-tlsmod14b.so: %m\n");
43       exit (1);
44     }
45
46   int (*fp) (void) = (int (*) (void)) dlsym (h, "in_dso2");
47   if (fp == NULL)
48     {
49       puts ("cannot find in_dso2");
50       exit (1);
51     }
52
53   result |= fp ();
54
55   return result;
56 }
57
58 # define TEST_FUNCTION do_test ()
59
60 #else
61
62 # define TEST_FUNCTION 0
63
64 #endif
65
66 #include "../test-skeleton.c"