Back to index

glibc  2.9
tst-tls16.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <stdio.h>
00003 
00004 static int
00005 do_test (void)
00006 {
00007   void *h = dlopen ("tst-tlsmod16a.so", RTLD_LAZY | RTLD_GLOBAL);
00008   if (h == NULL)
00009     {
00010       puts ("unexpectedly failed to open tst-tlsmod16a.so");
00011       exit (1);
00012     }
00013 
00014   void *p = dlsym (h, "tlsvar");
00015 
00016   /* This dlopen should indeed fail, because tlsvar was assigned to
00017      dynamic TLS, and the new module requests it to be in static TLS.
00018      However, there's a possibility that dlopen succeeds if the
00019      variable is, for whatever reason, assigned to static TLS, or if
00020      the module fails to require static TLS, or even if TLS is not
00021      supported.  */
00022   h = dlopen ("tst-tlsmod16b.so", RTLD_NOW | RTLD_GLOBAL);
00023   if (h == NULL)
00024     {
00025       return 0;
00026     }
00027 
00028   puts ("unexpectedly succeeded to open tst-tlsmod16b.so");
00029 
00030 
00031   void *(*fp) (void) = (void *(*) (void)) dlsym (h, "in_dso");
00032   if (fp == NULL)
00033     {
00034       puts ("cannot find in_dso");
00035       exit (1);
00036     }
00037 
00038   /* If the dlopen passes, at least make sure the address returned by
00039      dlsym is the same as that returned by the initial-exec access.
00040      If the variable was assigned to dynamic TLS during dlsym, this
00041      portion will fail.  */
00042   if (fp () != p)
00043     {
00044       puts ("returned values do not match");
00045       exit (1);
00046     }
00047 
00048   return 0;
00049 }
00050 
00051 #define TEST_FUNCTION do_test ()
00052 #include "../test-skeleton.c"