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