]> git.ipfire.org Git - thirdparty/glibc.git/blob - elf/tst-tls6.c
* elf/tst-tls4.c: Define an unused TLS variable here, so that no lazy
[thirdparty/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 #ifdef USE_TLS
9 # include "tls-macros.h"
10
11 /* This gives the executable a TLS segment so that even if the libc.so
12 it loads has none (i.e. --with-tls --without-__thread), ld.so will
13 permit loading of objects with TLS segments. */
14 COMMON_INT_DEF(loser);
15 #endif
16
17
18 #define TEST_FUNCTION do_test ()
19 static int
20 do_test (void)
21 {
22 #ifdef USE_TLS
23 static const char modname[] = "tst-tlsmod2.so";
24 int result = 0;
25 int *foop;
26 int *foop2;
27 int (*fp) (int, int *);
28 void *h;
29 int i;
30 int modid = -1;
31
32 for (i = 0; i < 10; ++i)
33 {
34 h = dlopen (modname, RTLD_LAZY);
35 if (h == NULL)
36 {
37 printf ("cannot open '%s': %s\n", modname, dlerror ());
38 exit (1);
39 }
40
41 /* Dirty test code here: we peek into a private data structure.
42 We make sure that the module gets assigned the same ID every
43 time. The value of the first round is used. */
44 if (modid == -1)
45 modid = ((struct link_map *) h)->l_tls_modid;
46 else if (((struct link_map *) h)->l_tls_modid != modid)
47 {
48 printf ("round %d: modid now %d, initially %d\n",
49 i, ((struct link_map *) h)->l_tls_modid, modid);
50 result = 1;
51 }
52
53 foop = dlsym (h, "foo");
54 if (foop == NULL)
55 {
56 printf ("cannot get symbol 'foo': %s\n", dlerror ());
57 exit (1);
58 }
59
60 *foop = 42 + i;
61
62 fp = dlsym (h, "in_dso");
63 if (fp == NULL)
64 {
65 printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
66 exit (1);
67 }
68
69 result |= fp (42 + i, foop);
70
71 foop2 = dlsym (h, "foo");
72 if (foop2 == NULL)
73 {
74 printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
75 exit (1);
76 }
77
78 if (foop != foop2)
79 {
80 puts ("address of 'foo' different the second time");
81 result = 1;
82 }
83 else if (*foop != 16)
84 {
85 puts ("foo != 16");
86 result = 1;
87 }
88
89 dlclose (h);
90 }
91
92 return result;
93 #else
94 return 0;
95 #endif
96 }
97
98
99 #include "../test-skeleton.c"