1#include <dlfcn.h>
2#include <mcheck.h>
3#include <stdio.h>
4#include <stdlib.h>
5
6
7int
8main (void)
9{
10 void *p1;
11 void *p2;
12 int (*fp) (void);
13 int result;
14
15 mtrace ();
16
17 p1 = dlopen (file: "dblloadmod1.so", RTLD_LAZY);
18 if (p1 == NULL)
19 {
20 printf (format: "cannot load dblloadmod1.so: %s\n", dlerror ());
21 exit (EXIT_FAILURE);
22 }
23
24 p2 = dlopen (file: "dblloadmod2.so", RTLD_LAZY);
25 if (p2 == NULL)
26 {
27 printf (format: "cannot load dblloadmod2.so: %s\n", dlerror ());
28 exit (EXIT_FAILURE);
29 }
30
31 if (dlclose (handle: p1) != 0)
32 {
33 printf (format: "error while closing dblloadmod1.so: %s\n", dlerror ());
34 exit (EXIT_FAILURE);
35 }
36
37 fp = dlsym (handle: p2, name: "xyzzy");
38 if (fp == NULL)
39 {
40 printf (format: "cannot get function \"xyzzy\": %s\n", dlerror ());
41 exit (EXIT_FAILURE);
42 }
43
44 result = fp ();
45
46 if (dlclose (handle: p2) != 0)
47 {
48 printf (format: "error while closing dblloadmod2.so: %s\n", dlerror ());
49 exit (EXIT_FAILURE);
50 }
51
52 return result;
53}
54

source code of glibc/elf/dblunload.c