1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 
5 #include <link.h>
6 
7 
8 static int
do_test(void)9 do_test (void)
10 {
11   static const char modname[] = "tst-tlsmod3.so";
12   int result = 0;
13   int (*fp) (void);
14   void *h;
15   int i;
16   int modid = -1;
17 
18   for (i = 0; i < 10; ++i)
19     {
20       h = dlopen (modname, RTLD_LAZY);
21       if (h == NULL)
22 	{
23 	  printf ("cannot open '%s': %s\n", modname, dlerror ());
24 	  exit (1);
25 	}
26 
27       /* Dirty test code here: we peek into a private data structure.
28 	 We make sure that the module gets assigned the same ID every
29 	 time.  The value of the first round is used.  */
30       if (modid == -1)
31 	modid = ((struct link_map *) h)->l_tls_modid;
32       else if (((struct link_map *) h)->l_tls_modid != (size_t) modid)
33 	{
34 	  printf ("round %d: modid now %zu, initially %d\n",
35 		  i, ((struct link_map *) h)->l_tls_modid, modid);
36 	  result = 1;
37 	}
38 
39       fp = dlsym (h, "in_dso2");
40       if (fp == NULL)
41 	{
42 	  printf ("cannot get symbol 'in_dso2': %s\n", dlerror ());
43 	  exit (1);
44 	}
45 
46       result |= fp ();
47 
48       dlclose (h);
49     }
50 
51   return result;
52 }
53 
54 
55 #include <support/test-driver.c>
56