1#include <dlfcn.h>
2#include <mcheck.h>
3#include <stdio.h>
4#include <stdlib.h>
5
6typedef int (*fn)(void);
7#define CHUNKS 1024
8#define REPEAT 64
9
10int
11main (void)
12{
13 void *h1;
14 void *h2;
15 fn **foopp;
16 fn bar, baz;
17 int i, j;
18 int n;
19 void *allocs[REPEAT][CHUNKS];
20
21 mtrace ();
22
23 /* Open the two objects. */
24 h1 = dlopen (file: "reldep6mod3.so", RTLD_LAZY);
25 if (h1 == NULL)
26 {
27 printf (format: "cannot open reldep6mod3.so: %s\n", dlerror ());
28 exit (status: 1);
29 }
30
31 foopp = dlsym (handle: h1, name: "foopp");
32 if (foopp == NULL)
33 {
34 printf (format: "cannot get address of \"foopp\": %s\n", dlerror ());
35 exit (status: 1);
36 }
37 n = (**foopp) ();
38 if (n != 20)
39 {
40 printf (format: "(**foopp)() return %d, not return 20\n", n);
41 exit (status: 1);
42 }
43
44 h2 = dlopen (file: "reldep6mod4.so", RTLD_LAZY);
45 if (h2 == NULL)
46 {
47 printf (format: "cannot open reldep6mod4.so: %s\n", dlerror ());
48 exit (status: 1);
49 }
50
51 baz = dlsym (handle: h2, name: "baz");
52 if (baz == NULL)
53 {
54 printf (format: "cannot get address of \"baz\": %s\n", dlerror ());
55 exit (status: 1);
56 }
57 if (baz () != 31)
58 {
59 printf (format: "baz() did not return 31\n");
60 exit (status: 1);
61 }
62
63 if (dlclose (handle: h1) != 0)
64 {
65 printf (format: "closing h1 failed: %s\n", dlerror ());
66 exit (status: 1);
67 }
68
69 /* Clobber memory. */
70 for (i = 0; i < REPEAT; ++i)
71 for (j = 0; j < CHUNKS; ++j)
72 allocs[i][j] = calloc (nmemb: 1, size: j + 1);
73
74 bar = dlsym (handle: h2, name: "bar");
75 if (bar == NULL)
76 {
77 printf (format: "cannot get address of \"bar\": %s\n", dlerror ());
78 exit (status: 1);
79 }
80 if (bar () != 40)
81 {
82 printf (format: "bar() did not return 40\n");
83 exit (status: 1);
84 }
85
86 baz = dlsym (handle: h2, name: "baz");
87 if (baz == NULL)
88 {
89 printf (format: "cannot get address of \"baz\": %s\n", dlerror ());
90 exit (status: 1);
91 }
92 if (baz () != 31)
93 {
94 printf (format: "baz() did not return 31\n");
95 exit (status: 1);
96 }
97
98 for (i = 0; i < REPEAT; ++i)
99 for (j = 0; j < CHUNKS; ++j)
100 free (ptr: allocs[i][j]);
101
102 if (dlclose (handle: h2) != 0)
103 {
104 printf (format: "closing h2 failed: %s\n", dlerror ());
105 exit (status: 1);
106 }
107
108 return 0;
109}
110

source code of glibc/elf/reldep6.c