Back to index

glibc  2.9
lateglobal.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <mcheck.h>
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 
00006 int
00007 main (void)
00008 {
00009   void *h[2];
00010   int fail;
00011   int (*fp) (void);
00012 
00013   mtrace ();
00014 
00015   h[0] = dlopen ("ltglobmod1.so", RTLD_LAZY);
00016   if (h[0] == NULL)
00017     {
00018       printf ("%s: cannot open %s: %s",
00019              __FUNCTION__, "ltglobmod1.so", dlerror ());
00020       exit (EXIT_FAILURE);
00021     }
00022   h[1] = dlopen ("ltglobmod2.so", RTLD_LAZY);
00023   if (h[1] == NULL)
00024     {
00025       printf ("%s: cannot open %s: %s",
00026              __FUNCTION__, "ltglobmod2.so", dlerror ());
00027       exit (EXIT_FAILURE);
00028     }
00029 
00030   puts ("loaded \"ltglobmod1.so\" without RTLD_GLOBAL");
00031 
00032   fp = dlsym (h[1], "foo");
00033   if (fp == NULL)
00034     {
00035       printf ("cannot get address of `foo': %s", dlerror ());
00036       exit (EXIT_FAILURE);
00037     }
00038 
00039   fail = fp ();
00040 
00041   puts ("back in main");
00042 
00043   dlclose (h[1]);
00044   dlclose (h[0]);
00045 
00046   return fail;
00047 }