1#include <dlfcn.h>
2#include <mcheck.h>
3#include <stdio.h>
4#include <stdlib.h>
5
6int
7main (void)
8{
9 void *h1;
10 void *h2;
11 int (*fp) (void);
12
13 mtrace ();
14
15 /* Open the two objects. */
16 h1 = dlopen (file: "reldepmod5.so", RTLD_LAZY);
17 if (h1 == NULL)
18 {
19 printf (format: "cannot open reldepmod5.so: %s\n", dlerror ());
20 exit (status: 1);
21 }
22 h2 = dlopen (file: "reldepmod6.so", RTLD_LAZY);
23 if (h2 == NULL)
24 {
25 printf (format: "cannot open reldepmod6.so: %s\n", dlerror ());
26 exit (status: 1);
27 }
28
29 /* Get the address of the variable in reldepmod1.so. */
30 fp = dlsym (handle: h2, name: "bar");
31 if (fp == NULL)
32 {
33 printf (format: "cannot get address of \"bar\": %s\n", dlerror ());
34 exit (status: 1);
35 }
36
37 /* Call the function. */
38 puts (s: "calling fp for the first time");
39 if (fp () != 0)
40 {
41 puts (s: "function \"call_me\" returned wrong result");
42 exit (status: 1);
43 }
44
45 /* Now close the first object. It must still be around since we have
46 an implicit dependency. */
47 if (dlclose (handle: h1) != 0)
48 {
49 printf (format: "closing h1 failed: %s\n", dlerror ());
50 exit (status: 1);
51 }
52
53 /* Calling the function must still work. */
54 puts (s: "calling fp for the second time");
55 if (fp () != 0)
56 {
57 puts (s: "function \"call_me\" the second time returned wrong result");
58 exit (status: 1);
59 }
60 puts (s: "second call suceeded as well");
61
62 /* Close the second object, we are done. */
63 if (dlclose (handle: h2) != 0)
64 {
65 printf (format: "closing h2 failed: %s\n", dlerror ());
66 exit (status: 1);
67 }
68
69 return 0;
70}
71

source code of glibc/elf/reldep5.c