Mention IFUNC enhancements to testsuite in NEWS.
[platform/upstream/glibc.git] / elf / tst-tls6.c
1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 #include <link.h>
6 #include <tls.h>
7
8
9 #define TEST_FUNCTION do_test ()
10 static int
11 do_test (void)
12 {
13   static const char modname[] = "tst-tlsmod2.so";
14   int result = 0;
15   int *foop;
16   int *foop2;
17   int (*fp) (int, int *);
18   void *h;
19   int i;
20   int modid = -1;
21
22   for (i = 0; i < 10; ++i)
23     {
24       h = dlopen (modname, RTLD_LAZY);
25       if (h == NULL)
26         {
27           printf ("cannot open '%s': %s\n", modname, dlerror ());
28           exit (1);
29         }
30
31       /* Dirty test code here: we peek into a private data structure.
32          We make sure that the module gets assigned the same ID every
33          time.  The value of the first round is used.  */
34       if (modid == -1)
35         modid = ((struct link_map *) h)->l_tls_modid;
36       else if (((struct link_map *) h)->l_tls_modid != modid)
37         {
38           printf ("round %d: modid now %zd, initially %d\n",
39                   i, ((struct link_map *) h)->l_tls_modid, modid);
40           result = 1;
41         }
42
43       foop = dlsym (h, "foo");
44       if (foop == NULL)
45         {
46           printf ("cannot get symbol 'foo': %s\n", dlerror ());
47           exit (1);
48         }
49
50       *foop = 42 + i;
51
52       fp = dlsym (h, "in_dso");
53       if (fp == NULL)
54         {
55           printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
56           exit (1);
57         }
58
59       result |= fp (42 + i, foop);
60
61       foop2 = dlsym (h, "foo");
62       if (foop2 == NULL)
63         {
64           printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
65           exit (1);
66         }
67
68       if (foop != foop2)
69         {
70           puts ("address of 'foo' different the second time");
71           result = 1;
72         }
73       else if (*foop != 16)
74         {
75           puts ("foo != 16");
76           result = 1;
77         }
78
79       dlclose (h);
80     }
81
82   return result;
83 }
84
85
86 #include "../test-skeleton.c"