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 open dblloadmod1.so: %s\n", dlerror ());
21 exit (EXIT_FAILURE);
22 }
23
24 p2 = dlopen (file: "dblloadmod2.so", RTLD_LAZY);
25 if (p1 == NULL)
26 {
27 printf (format: "cannot open dblloadmod2.so: %s\n", dlerror ());
28 exit (EXIT_FAILURE);
29 }
30
31 fp = dlsym (handle: p1, name: "foo");
32 if (fp == NULL)
33 {
34 printf (format: "cannot get function \"foo\": %s\n", dlerror ());
35 exit (EXIT_FAILURE);
36 }
37
38 result = fp ();
39
40 if (dlclose (handle: p1) != 0)
41 {
42 printf (format: "error while closing dblloadmod1.so: %s\n", dlerror ());
43 exit (EXIT_FAILURE);
44 }
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/dblload.c