Blame elf/reldep5.c

Packit 6c4009
#include <dlfcn.h>
Packit 6c4009
#include <mcheck.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
main (void)
Packit 6c4009
{
Packit 6c4009
  void *h1;
Packit 6c4009
  void *h2;
Packit 6c4009
  int (*fp) (void);
Packit 6c4009
Packit 6c4009
  mtrace ();
Packit 6c4009
Packit 6c4009
  /* Open the two objects.  */
Packit 6c4009
  h1 = dlopen ("reldepmod5.so", RTLD_LAZY);
Packit 6c4009
  if (h1 == NULL)
Packit 6c4009
    {
Packit 6c4009
      printf ("cannot open reldepmod5.so: %s\n", dlerror ());
Packit 6c4009
      exit (1);
Packit 6c4009
    }
Packit 6c4009
  h2 = dlopen ("reldepmod6.so", RTLD_LAZY);
Packit 6c4009
  if (h2 == NULL)
Packit 6c4009
    {
Packit 6c4009
      printf ("cannot open reldepmod6.so: %s\n", dlerror ());
Packit 6c4009
      exit (1);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* Get the address of the variable in reldepmod1.so.  */
Packit 6c4009
  fp = dlsym (h2, "bar");
Packit 6c4009
  if (fp == NULL)
Packit 6c4009
    {
Packit 6c4009
      printf ("cannot get address of \"bar\": %s\n", dlerror ());
Packit 6c4009
      exit (1);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* Call the function.  */
Packit 6c4009
  puts ("calling fp for the first time");
Packit 6c4009
  if (fp () != 0)
Packit 6c4009
    {
Packit 6c4009
      puts ("function \"call_me\" returned wrong result");
Packit 6c4009
      exit (1);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* Now close the first object.  It must still be around since we have
Packit 6c4009
     an implicit dependency.  */
Packit 6c4009
  if (dlclose (h1) != 0)
Packit 6c4009
    {
Packit 6c4009
      printf ("closing h1 failed: %s\n", dlerror ());
Packit 6c4009
      exit (1);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* Calling the function must still work.  */
Packit 6c4009
  puts ("calling fp for the second time");
Packit 6c4009
  if (fp () != 0)
Packit 6c4009
    {
Packit 6c4009
      puts ("function \"call_me\" the second time returned wrong result");
Packit 6c4009
      exit (1);
Packit 6c4009
    }
Packit 6c4009
  puts ("second call suceeded as well");
Packit 6c4009
Packit 6c4009
  /* Close the second object, we are done.  */
Packit 6c4009
  if (dlclose (h2) != 0)
Packit 6c4009
    {
Packit 6c4009
      printf ("closing h2 failed: %s\n", dlerror ());
Packit 6c4009
      exit (1);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return 0;
Packit 6c4009
}