Back to index

glibc  2.9
tst-tls-dlinfo.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 
00005 #include <tls.h>
00006 
00007 
00008 #define TEST_FUNCTION do_test ()
00009 static int
00010 do_test (void)
00011 {
00012   static const char modname[] = "tst-tlsmod2.so";
00013   int result = 0;
00014   int *foop;
00015   int (*fp) (int, int *);
00016   void *h;
00017 
00018   h = dlopen (modname, RTLD_LAZY);
00019   if (h == NULL)
00020     {
00021       printf ("cannot open '%s': %s\n", modname, dlerror ());
00022       exit (1);
00023     }
00024 
00025   fp = dlsym (h, "in_dso");
00026   if (fp == NULL)
00027     {
00028       printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
00029       exit (1);
00030     }
00031 
00032   size_t modid = -1;
00033   if (dlinfo (h, RTLD_DI_TLS_MODID, &modid))
00034     {
00035       printf ("dlinfo RTLD_DI_TLS_MODID failed: %s\n", dlerror ());
00036       result = 1;
00037     }
00038   else
00039     printf ("dlinfo says TLS module ID %Zu\n", modid);
00040 
00041   void *block;
00042   if (dlinfo (h, RTLD_DI_TLS_DATA, &block))
00043     {
00044       printf ("dlinfo RTLD_DI_TLS_DATA failed: %s\n", dlerror ());
00045       result = 1;
00046     }
00047   else if (block != NULL)
00048     {
00049       printf ("dlinfo RTLD_DI_TLS_DATA says %p but should be unallocated\n",
00050              block);
00051       result = 1;
00052     }
00053 
00054   result |= fp (0, NULL);
00055 
00056   foop = dlsym (h, "foo");
00057   if (foop == NULL)
00058     {
00059       printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
00060       exit (1);
00061     }
00062   if (*foop != 16)
00063     {
00064       puts ("foo != 16");
00065       result = 1;
00066     }
00067 
00068   /* Now the module's TLS block has been used and should appear.  */
00069   if (dlinfo (h, RTLD_DI_TLS_DATA, &block))
00070     {
00071       printf ("dlinfo RTLD_DI_TLS_DATA failed the second time: %s\n",
00072              dlerror ());
00073       result = 1;
00074     }
00075   else if (block != foop)
00076     {
00077       printf ("dlinfo RTLD_DI_TLS_DATA says %p but should be %p\n",
00078              block, foop);
00079       result = 1;
00080     }
00081 
00082   dlclose (h);
00083 
00084   return result;
00085 }
00086 
00087 
00088 #include "../test-skeleton.c"