(linenum→info "unix/slp.c:2238")

glibc/2.7/elf/lateglobal.c

    1: #include <dlfcn.h>
    2: #include <mcheck.h>
    3: #include <stdio.h>
    4: #include <stdlib.h>
    5: 
    6: int
    7: main (void)
    8: {
    9:   void *h[2];
   10:   int fail;
   11:   int (*fp) (void);
   12: 
   13:   mtrace ();
   14: 
   15:   h[0] = dlopen ("ltglobmod1.so", RTLD_LAZY);
   16:   if (h[0] == NULL)
   17:     {
   18:       printf ("%s: cannot open %s: %s",
   19:               __FUNCTION__, "ltglobmod1.so", dlerror ());
   20:       exit (EXIT_FAILURE);
   21:     }
   22:   h[1] = dlopen ("ltglobmod2.so", RTLD_LAZY);
   23:   if (h[1] == NULL)
   24:     {
   25:       printf ("%s: cannot open %s: %s",
   26:               __FUNCTION__, "ltglobmod2.so", dlerror ());
   27:       exit (EXIT_FAILURE);
   28:     }
   29: 
   30:   puts ("loaded \"ltglobmod1.so\" without RTLD_GLOBAL");
   31: 
   32:   fp = dlsym (h[1], "foo");
   33:   if (fp == NULL)
   34:     {
   35:       printf ("cannot get address of `foo': %s", dlerror ());
   36:       exit (EXIT_FAILURE);
   37:     }
   38: 
   39:   fail = fp ();
   40: 
   41:   puts ("back in main");
   42: 
   43:   dlclose (h[1]);
   44:   dlclose (h[0]);
   45: 
   46:   return fail;
   47: }
Syntax (Markdown)