|
Packit Service |
82fcde |
#include <dlfcn.h>
|
|
Packit Service |
82fcde |
#include <error.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 |
int (*fp1) (int);
|
|
Packit Service |
82fcde |
void *h2;
|
|
Packit Service |
82fcde |
int (*fp2) (int);
|
|
Packit Service |
82fcde |
int res1;
|
|
Packit Service |
82fcde |
int res2;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
mtrace ();
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
h1 = dlopen ("testobj1.so", RTLD_LAZY);
|
|
Packit Service |
82fcde |
if (h1 == NULL)
|
|
Packit Service |
82fcde |
error (EXIT_FAILURE, 0, "while loading `%s': %s", "testobj1.so",
|
|
Packit Service |
82fcde |
dlerror ());
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
h2 = dlopen ("testobj1_1.so", RTLD_LAZY);
|
|
Packit Service |
82fcde |
if (h1 == NULL)
|
|
Packit Service |
82fcde |
error (EXIT_FAILURE, 0, "while loading `%s': %s", "testobj1_1.so",
|
|
Packit Service |
82fcde |
dlerror ());
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
fp1 = dlsym (h1, "obj1func1");
|
|
Packit Service |
82fcde |
if (fp1 == NULL)
|
|
Packit Service |
82fcde |
error (EXIT_FAILURE, 0, "getting `obj1func1' in `%s': %s",
|
|
Packit Service |
82fcde |
"testobj1.so", dlerror ());
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
fp2 = dlsym (h2, "obj1func1");
|
|
Packit Service |
82fcde |
if (fp2 == NULL)
|
|
Packit Service |
82fcde |
error (EXIT_FAILURE, 0, "getting `obj1func1' in `%s': %s",
|
|
Packit Service |
82fcde |
"testobj1_1.so", dlerror ());
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
res1 = fp1 (10);
|
|
Packit Service |
82fcde |
res2 = fp2 (10);
|
|
Packit Service |
82fcde |
printf ("fp1(10) = %d\nfp2(10) = %d\n", res1, res2);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (dlclose (h1) != 0)
|
|
Packit Service |
82fcde |
error (EXIT_FAILURE, 0, "cannot close testobj1.so: %s\n", dlerror ());
|
|
Packit Service |
82fcde |
if (dlclose (h2) != 0)
|
|
Packit Service |
82fcde |
error (EXIT_FAILURE, 0, "cannot close testobj1_1.so: %s\n", dlerror ());
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
return res1 != 42 || res2 != 72;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
extern int foo (int a);
|
|
Packit Service |
82fcde |
int
|
|
Packit Service |
82fcde |
foo (int a)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
return a + 10;
|
|
Packit Service |
82fcde |
}
|