|
Packit Service |
82fcde |
#include <dlfcn.h>
|
|
Packit Service |
82fcde |
#include <mcheck.h>
|
|
Packit Service |
82fcde |
#include <stdio.h>
|
|
Packit Service |
82fcde |
#include <stdlib.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
int
|
|
Packit Service |
82fcde |
main (void)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
void *h1;
|
|
Packit Service |
82fcde |
void *h2;
|
|
Packit Service |
82fcde |
int (*fp) (void);
|
|
Packit Service |
82fcde |
int *vp;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
mtrace ();
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Open the two objects. */
|
|
Packit Service |
82fcde |
h1 = dlopen ("reldepmod1.so", RTLD_LAZY | RTLD_GLOBAL);
|
|
Packit Service |
82fcde |
if (h1 == NULL)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
printf ("cannot open reldepmod1.so: %s\n", dlerror ());
|
|
Packit Service |
82fcde |
exit (1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
h2 = dlopen ("reldepmod4.so", RTLD_LAZY);
|
|
Packit Service |
82fcde |
if (h2 == NULL)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
printf ("cannot open reldepmod4.so: %s\n", dlerror ());
|
|
Packit Service |
82fcde |
exit (1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Get the address of the variable in reldepmod1.so. */
|
|
Packit Service |
82fcde |
vp = dlsym (h1, "some_var");
|
|
Packit Service |
82fcde |
if (vp == NULL)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
printf ("cannot get address of \"some_var\": %s\n", dlerror ());
|
|
Packit Service |
82fcde |
exit (1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
*vp = 42;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Get the function `call_me' in the second object. This has a
|
|
Packit Service |
82fcde |
dependency which is resolved by a definition in reldepmod1.so. */
|
|
Packit Service |
82fcde |
fp = dlsym (h2, "call_me");
|
|
Packit Service |
82fcde |
if (fp == NULL)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
printf ("cannot get address of \"call_me\": %s\n", dlerror ());
|
|
Packit Service |
82fcde |
exit (1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Call the function. */
|
|
Packit Service |
82fcde |
if (fp () != 0)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("function \"call_me\" returned wrong result");
|
|
Packit Service |
82fcde |
exit (1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Now close the first object. If must still be around since we have
|
|
Packit Service |
82fcde |
an implicit dependency. */
|
|
Packit Service |
82fcde |
if (dlclose (h1) != 0)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
printf ("closing h1 failed: %s\n", dlerror ());
|
|
Packit Service |
82fcde |
exit (1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Open the first object again. */
|
|
Packit Service |
82fcde |
h1 = dlopen ("reldepmod1.so", RTLD_LAZY | RTLD_GLOBAL);
|
|
Packit Service |
82fcde |
if (h1 == NULL)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
printf ("cannot open reldepmod1.so the second time: %s\n", dlerror ());
|
|
Packit Service |
82fcde |
exit (1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Get the variable address again. */
|
|
Packit Service |
82fcde |
vp = dlsym (h1, "some_var");
|
|
Packit Service |
82fcde |
if (vp == NULL)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
printf ("cannot get address of \"some_var\" the second time: %s\n",
|
|
Packit Service |
82fcde |
dlerror ());
|
|
Packit Service |
82fcde |
exit (1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* The variable now must have its originial value. */
|
|
Packit Service |
82fcde |
if (*vp != 0)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("variable \"some_var\" not reset");
|
|
Packit Service |
82fcde |
exit (1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Close the first object again, we are done. */
|
|
Packit Service |
82fcde |
if (dlclose (h1) != 0)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
printf ("closing h1 failed: %s\n", dlerror ());
|
|
Packit Service |
82fcde |
exit (1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
if (dlclose (h2) != 0)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
printf ("closing h2 failed: %s\n", dlerror ());
|
|
Packit Service |
82fcde |
exit (1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
return 0;
|
|
Packit Service |
82fcde |
}
|