Back to index

glibc  2.9
tst-tls8.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 
00005 #include <link.h>
00006 #include <tls.h>
00007 
00008 
00009 #define TEST_FUNCTION do_test ()
00010 static int
00011 do_test (void)
00012 {
00013   static const char modname1[] = "$ORIGIN/tst-tlsmod3.so";
00014   static const char modname2[] = "$ORIGIN/tst-tlsmod4.so";
00015   int result = 0;
00016   int (*fp1) (void);
00017   int (*fp2) (int, int *);
00018   void *h1;
00019   void *h2;
00020   int i;
00021   size_t modid1 = (size_t) -1;
00022   size_t modid2 = (size_t) -1;
00023   int *bazp;
00024 
00025   for (i = 0; i < 10; ++i)
00026     {
00027       h1 = dlopen (modname1, RTLD_LAZY);
00028       if (h1 == NULL)
00029        {
00030          printf ("cannot open '%s': %s\n", modname1, dlerror ());
00031          exit (1);
00032        }
00033 
00034       /* Dirty test code here: we peek into a private data structure.
00035         We make sure that the module gets assigned the same ID every
00036         time.  The value of the first round is used.  */
00037       if (modid1 == (size_t) -1)
00038        modid1 = ((struct link_map *) h1)->l_tls_modid;
00039       else if (((struct link_map *) h1)->l_tls_modid != modid1)
00040        {
00041          printf ("round %d: modid now %zd, initially %zd\n",
00042                 i, ((struct link_map *) h1)->l_tls_modid, modid1);
00043          result = 1;
00044        }
00045 
00046       fp1 = dlsym (h1, "in_dso2");
00047       if (fp1 == NULL)
00048        {
00049          printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
00050          exit (1);
00051        }
00052 
00053       result |= fp1 ();
00054 
00055 
00056 
00057       h2 = dlopen (modname2, RTLD_LAZY);
00058       if (h2 == NULL)
00059        {
00060          printf ("cannot open '%s': %s\n", modname2, dlerror ());
00061          exit (1);
00062        }
00063 
00064       /* Dirty test code here: we peek into a private data structure.
00065         We make sure that the module gets assigned the same ID every
00066         time.  The value of the first round is used.  */
00067       if (modid2 == (size_t) -1)
00068        modid2 = ((struct link_map *) h1)->l_tls_modid;
00069       else if (((struct link_map *) h1)->l_tls_modid != modid2)
00070        {
00071          printf ("round %d: modid now %zd, initially %zd\n",
00072                 i, ((struct link_map *) h1)->l_tls_modid, modid2);
00073          result = 1;
00074        }
00075 
00076       bazp = dlsym (h2, "baz");
00077       if (bazp == NULL)
00078        {
00079          printf ("cannot get symbol 'baz' in %s\n", modname2);
00080          exit (1);
00081        }
00082 
00083       *bazp = 42 + i;
00084 
00085       fp2 = dlsym (h2, "in_dso");
00086       if (fp2 == NULL)
00087        {
00088          printf ("cannot get symbol 'in_dso' in %s\n", modname2);
00089          exit (1);
00090        }
00091 
00092       result |= fp2 (42 + i, bazp);
00093 
00094       dlclose (h1);
00095       dlclose (h2);
00096 
00097 
00098       h1 = dlopen (modname1, RTLD_LAZY);
00099       if (h1 == NULL)
00100        {
00101          printf ("cannot open '%s': %s\n", modname1, dlerror ());
00102          exit (1);
00103        }
00104 
00105       /* Dirty test code here: we peek into a private data structure.
00106         We make sure that the module gets assigned the same ID every
00107         time.  The value of the first round is used.  */
00108       if (((struct link_map *) h1)->l_tls_modid != modid1)
00109        {
00110          printf ("round %d: modid now %zd, initially %zd\n",
00111                 i, ((struct link_map *) h1)->l_tls_modid, modid1);
00112          result = 1;
00113        }
00114 
00115       fp1 = dlsym (h1, "in_dso2");
00116       if (fp1 == NULL)
00117        {
00118          printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
00119          exit (1);
00120        }
00121 
00122       result |= fp1 ();
00123 
00124 
00125 
00126       h2 = dlopen (modname2, RTLD_LAZY);
00127       if (h2 == NULL)
00128        {
00129          printf ("cannot open '%s': %s\n", modname2, dlerror ());
00130          exit (1);
00131        }
00132 
00133       /* Dirty test code here: we peek into a private data structure.
00134         We make sure that the module gets assigned the same ID every
00135         time.  The value of the first round is used.  */
00136       if (((struct link_map *) h1)->l_tls_modid != modid2)
00137        {
00138          printf ("round %d: modid now %zd, initially %zd\n",
00139                 i, ((struct link_map *) h1)->l_tls_modid, modid2);
00140          result = 1;
00141        }
00142 
00143       bazp = dlsym (h2, "baz");
00144       if (bazp == NULL)
00145        {
00146          printf ("cannot get symbol 'baz' in %s\n", modname2);
00147          exit (1);
00148        }
00149 
00150       *bazp = 62 + i;
00151 
00152       fp2 = dlsym (h2, "in_dso");
00153       if (fp2 == NULL)
00154        {
00155          printf ("cannot get symbol 'in_dso' in %s\n", modname2);
00156          exit (1);
00157        }
00158 
00159       result |= fp2 (62 + i, bazp);
00160 
00161       /* This time the dlclose calls are in reverse order.  */
00162       dlclose (h2);
00163       dlclose (h1);
00164     }
00165 
00166   return result;
00167 }
00168 
00169 
00170 #include "../test-skeleton.c"